home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / open / easyansi.lzh / EASYANSI.TXT
Text File  |  1989-04-11  |  21KB  |  515 lines

  1.            I WISH I COULD MAKE THIS THING DO...
  2.                         - or -
  3.                     Using ANSI.SYS
  4.  
  5.  
  6. I hesitate to use ANSI.SYS in the title because I fear that
  7. everyone who sees that will delegate this article to the round
  8. file without reading it, because the subject seems to have been
  9. beat to death.  I am registered with the Guiness Book of Records
  10. as one of the worlds fastest page turners when I spot an article
  11. dealing with the more arcane aspects of DOS.  The problem seems
  12. to be not that the equipment/software is incapable of a lot of
  13. things, but that they made it so bloody difficult to get at these
  14. facilities.  I know that I am not the only one to feel this way,
  15. as entire software companies have been launched on such things as
  16. keyboard macro programs and screen format programs, yet DOS has
  17. the software built in to do all of these things in satisfactory
  18. fashion.
  19.  
  20. I was inspired to take another look at ANSI.SYS after a recent
  21. column in PC Magazine published a program called ANSI.COM as a
  22. replacement for ANSI.SYS on the premise that ANSI.COM is faster,
  23. can be removed from memory when not being used, and supports 43
  24. line EGA displays.  I never got much of a chance to find out if
  25. this is true, because the program did not agree with either of
  26. the keyboard enhancers that I normally use, and I wasn't curious
  27. enough to disable my keyboard enhancer(s) to find out how
  28. ANSI.COM works.  They did make the valid point, though, that most
  29. of us don't use these things because they are too difficult to
  30. get at.  I relate to this: as much as I enjoy digging around in
  31. the operating system software, I have balked at using ANSI.SYS
  32. for any of the things that it is supposed to do because one look
  33. at the command tables (after I found out where to find them) just
  34. gave me the impression of having to learn one more computer
  35. language.  I'm sorry, folks, but 16 or 18 languages is enough. 
  36. I'm not going to plow through this one just to get some screen
  37. colors...
  38.  
  39. What turned the corner for me was not the article on ANSI.COM
  40. itself, but a little program listing named ESCAPE buried inside
  41. the article that allows you to send escape code sequences to ANSI
  42. directly from the keyboard.  This doesn't sound too exciting in
  43. itself, but allow me to explain the problem before handing out a
  44. solution.
  45.  
  46. If you have read that ANSI.SYS can be used to set default screen
  47. colors and redefine the keyboard, you may have actually gone to
  48. the DOS manual to try to figure out how to do this.  Look up
  49. ANSI.SYS.  All you will learn is that you must install ANSI.SYS
  50. with a DEVICE command in your CONFIG.SYS file.  Not one word on
  51. how to use it.  You may have read somewhere that to send codes to
  52. ANSI.SYS that you can use the PROMPT command.  Look up PROMPT. 
  53. You will find instructions on how to make "meta-strings" to send
  54. commands to DOS to make custom DOS prompts.  (Come on, IBM, do we
  55. need ANOTHER adluxian obfuscation? (Alright, alright - I made up
  56. at least ONE of those words.))  Seems like we are getting farther
  57. away from what we were trying to find out.  However, buried in
  58. the list of "meta-strings" is what we need to talk to ANSI - a
  59. character that sends the Escape character to ANSI.  There is even
  60. an example of the syntax to send codes to ANSI, but after that
  61. you are on your own - you are referred to the DOS Technical
  62. Reference manual for a discussion of how to use ANSI.SYS.  Worse
  63. yet, you are given none of the ANSI codes that are supposed to do
  64. all of these wonderful things.  Well, the DOS Technical Reference
  65. manual is only $150 or so - I guess that's worth it to get the
  66. half dozen or so codes that I want and will never look at
  67. again... (Seriously, look for a book by Thom Hogan called The
  68. Programmer's PC Sourcebook from Microsoft Press ($24.95 retail)
  69. that has all of the obscure tables from every source imaginable
  70. including ANSI codes.)
  71.  
  72. O.K., so we now have a method to send control codes to ANSI,
  73. albeit somewhat arcane, but if you are like me, you already have
  74. your PROMPT set and don't want to use the PROMPT command and mess
  75. it up with all this experimenting.  Now we finally get to the
  76. ESCAPE program.
  77.  
  78. If you are comfortable with DEBUG, fire it up and enter the
  79. program directly, as follows:
  80.  
  81.    -a <Enter>            ;assemble directly into memory
  82.    xxxx:0100 mov si,0080 ;
  83.    xxxx:0103 mov cl,[si] ;
  84.    xxxx:0105 xor ch,ch   ;
  85.    xxxx:0107 inc cx      ;
  86.    xxxx:0108 mov word ptr [si],5B1B ;
  87.    xxxx:010C lodsb       ;
  88.    xxxx:010D int 29      ;DOS internal screen write routine
  89.    xxxx:010F loop 010C   ;
  90.    xxxx:0111 ret         ;
  91.    xxxx:0112 <Enter>     ;press <Enter> - tells DEBUG you're done
  92.    -n esc.com            ;name the program ESC.COM
  93.    -rcx                  ;read CX register
  94.    CX 0000               ;DEBUG replies with this
  95.    :12                   ;set CX to save 12H bytes
  96.    -w                    ;write the file to disk
  97.    Writing 0012 bytes    ;DEBUG replies with this
  98.    -q                    ;quit DEBUG - back to DOS
  99.  
  100. This will leave a small program on your disk named ESC.COM that
  101. we will get to in a moment.
  102.  
  103. If you don't have enough aspirin to deal with DEBUG, you may send
  104. the program to DEBUG as a Script file (ASCII text) and DEBUG will
  105. do the work from that.  From your favorite word processor, type
  106. the following:
  107.  
  108.    A<Enter>
  109.    MOV SI,0080<Enter>
  110.    MOV CL,[SI]<Enter>
  111.    XOR CH,CH<Enter>
  112.    INC CX<Enter>
  113.    MOV Word Ptr [SI],5B1B<Enter>
  114.    LODSB<Enter>
  115.    INT 29<Enter>
  116.    LOOP 010C<Enter>
  117.    RET<Enter>
  118.    (press <Enter> key once right here)
  119.    N ESC.COM<Enter>
  120.    RCX<Enter>
  121.    12<Enter>
  122.    W<Enter>
  123.    Q<Enter>
  124.  
  125. The text does not have to be capitalized.  There do have to be
  126. spaces where shown, however.  Press <Enter> at the end of each
  127. line as shown to start a new line for the next command.  The
  128. <Enter> key is pressed once between RET and N ESC.COM to send an
  129. extra <Enter> to DEBUG in the right place.  Save the document in
  130. your word processor's text mode or DOS text mode or non-document
  131. mode or whatever your word processor calls and ASCII file, and
  132. give it the name ESC.SCR.  Check ESC.SCR before sending it to
  133. DEBUG with the TYPE command, thus:
  134.  
  135.    DOSPROMPT>type esc.scr<Enter>
  136.  
  137. the screen should look almost exactly like this:
  138.  
  139. A
  140. MOV SI,0080
  141. MOV CL,[SI]
  142. XOR CH,CH
  143. INC CX
  144. MOV Word Ptr [SI],5B1B
  145. LODSB
  146. INT 29
  147. LOOP 010C
  148. RET
  149.  
  150. N ESC.COM
  151. RCX
  152. 12
  153. W
  154. Q
  155.  
  156. If it does, the script file should work O.K.  Now, the dangerous
  157. part.  (Not really - if it doesn't work, the worst that will
  158. happen is that you will have to reboot and may have a strange new
  159. file on your disk that probably won't work.  Just delete it, edit
  160. the script file carefully for mistakes, and try again.)
  161.  
  162. Move ESC.SCR into the same directory as DEBUG.  From the DOS
  163. prompt, enter the following command:
  164.  
  165.    DOSPROMPT>debug < esc.scr<Enter>
  166.  
  167. Things will whir and clunk for a bit, then the DOS prompt will
  168. come back if all went well.  If all didn't go well, exercise your
  169. favorite expletives, reboot the computer, edit the script file
  170. for errors, and try again.  When it works, do a DIR command and
  171. look for a new file called ESC.COM.
  172.  
  173. Now the fun part.  The ESC program may be used to send Escape
  174. codes to ANSI, but what codes are we going to send?  -- thought
  175. you'd never ask...
  176.  
  177. ===============================================================
  178. TABLES OF ANSI CODES TO BE USED WITH ESC.COM
  179.  
  180. Note - all numbers are DECIMAL because this is what ANSI expects.
  181.  
  182. Table A - IBM ANSI Set Graphics Rendition control sequences
  183.           (in English, this means screen manipulation codes)
  184.  
  185. Code      What it does
  186. ----------------------------------------------------------------
  187. 0 -  All attributes off (normal white on black screen)
  188. 1 -  Bold on (high intensity)
  189. 4 -  Underline (mono screen) or Blue foreground (color screen)
  190. 5 -  Blink on
  191. 7 -  Reverse video on
  192. 8 -  "Cancelled" on (invisible characters - use for secret stuff)
  193. 30 - Black foreground (characters)
  194. 31 - Red foreground
  195. 32 - Green foreground
  196. 33 - Yellow foreground
  197. 34 - Underline (mono screen) or Blue foreground (color screen)
  198. 35 - Magenta foreground
  199. 36 - Cyan foreground
  200. 37 - White foreground
  201. 40 - Black background
  202. 41 - Red background
  203. 42 - Green background
  204. 43 - Yellow background
  205. 44 - Blue background
  206. 45 - Magenta background
  207. 46 - Cyan background
  208. 47 - White background
  209.  
  210.  
  211.  
  212. Table B - Video Modes (to set your screen resolutions - if you   
  213.           have the hardware to run the mode you are trying to    
  214.           use.)
  215.  
  216. Code      What it does
  217. ----------------------------------------------------------------
  218. 0 -  40x25 black and white
  219. 1 -  40x25 color
  220. 2 -  80x25 black and white
  221. 3 -  80x25 color
  222. 4 -  320x200 color
  223. 5 -  320x200 black and white
  224. 6 -  640x200 black and white
  225. 7 -  Wrap at end of line (DOS default - start new line if you go 
  226.      past the end of the one you are on.
  227. 14 - 640x200 color EGA
  228. 15 - 640x350 mono EGA
  229. 16 - 640x350 color EGA
  230. 17 - 640x480 color VGA
  231. 19 - 320x200 color VGA
  232.  
  233.  
  234.  
  235. Table C - Extended ASCII Codes (to redefine the keyboard keys)
  236.           <NOTE> - These codes require extended format - see text
  237.  
  238. Code      What key or key combination it belongs to
  239. ---------------------------------------------------------------
  240. 3 -       Null (does nothing)
  241. 15 -      Shift+Tab
  242.  
  243. Some of the following codes are with the SHIFT, CONTROL, or ALT
  244. key pressed at the same time.  Read the table carefully.
  245.  
  246. ALT+key - Q   U   E   R   T   Y   U   I   O   P
  247. Code -    16  17  18  19  20  21  22  23  24  25
  248.  
  249. ALT+key - A   S   D   F   G   H   J   K   L
  250. Code    - 30  31  32  33  34  35  36  37  38
  251.  
  252. ALT+key - Z   X   C   V   B   N   M
  253. Code    - 44  45  46  47  48  49  50
  254.  
  255. Key     - F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11  F12
  256. Code    - 59  60  61  62  63  64  65  66  67  68   133  134
  257.  
  258. SHFT+key- F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11  F12
  259. Code    - 84  85  86  87  88  89  90  91  92  93   135  136
  260.  
  261. CTRL+key- F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11  F12
  262. Code    - 94  95  96  97  98  99  100 101 102 103  137  138
  263.  
  264. ALT+key - F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11  F12
  265. Code    - 104 105 106 107 108 109 110 111 112 113  139  140
  266.  
  267. NOTE - Extended ASCII code for use with this table is a two-byte
  268.        code: the byte 00 followed by ";", then the code in this  
  269.      table.  Ex: SHFT+F1 is 00;84.  CTRL+F1 is 00;94
  270.  
  271. ===============================================================
  272.  
  273.  
  274. Note that Table C is incomplete, but I have provided the best
  275. keyboard candidates for reassignment, and that there are enough
  276. clues to find the rest of the key codes.
  277.  
  278. Okay so now what do we do with this?  Well for starters, notice
  279. that DOS make almost no use of the function keys.  There is a
  280. small command line editor assigned to F1 through F4 that almost
  281. no one uses because almost no one knows that it is there.  Try
  282. this - if you have previously put something in the keyboard
  283. buffer (typed in something and pressed <Enter>), the function
  284. keys will do the following for you:
  285.  
  286. F1 = puts next character from the command buffer on the command  
  287.      line.
  288.  
  289. F2 = puts all characters from the command buffer up to the next  
  290.      character you type on the command line (e.g. <F2> <s>       
  291.      supplies all characters up to "s").
  292.  
  293. F3 = puts all characters from the command buffer on the command  
  294.      line. (this is the one everyone has seen)
  295.  
  296. F4 = Skips all characters from the command buffer up to the next 
  297.      character you type (e.g. <F4> <s> skips to "s").
  298.  
  299. Ins= Insert a character at the current spot in command buffer.
  300.  
  301. Del= Delete a character at the current spot in command buffer.
  302.  
  303. Try this - from the DOS prompt, type in the following:
  304.  
  305.    DOSPROMPT>difr b:<Enter>      (yes, including the mistake)
  306.  
  307. For those of you who are perfect, you've never seen the error
  308. message;
  309.  
  310.    Bad Command or Filename
  311.  
  312. If I haven't seen it today, its because my computer is unplugged.
  313.  
  314. Normally, you would have to retype the command, but try this -
  315. press the <F2> key then the <f> key.  The command line now looks
  316. like this:
  317.  
  318.    DOSPROMPT>di_
  319.  
  320. The old command line has been placed on the new command line up
  321. to the wrong character (f).  Press the DEL key on the keyboard. 
  322. You just erased the "f" from the command buffer.  Now press the
  323. <F3> key to get the rest of the line.  The command line now looks
  324. like this:
  325.  
  326.    DOSPROMPT>dir b:
  327.  
  328. How 'bout that!! correct spelling!  When you press <Enter> the
  329. command will execute. (and you will probably get a new error
  330. because you forgot to put a disk in drive b:)
  331.  
  332. Trivial example, but try it on something like
  333. CD\DEEP\DARK\DANK\DUNGEON and it saves a lot of retyping.  Only
  334. four commands to learn and it neatly covers 95 percent of the
  335. mistakes I make.  Plus you now find that you don't have to spend
  336. $50 on that command line editor program that will take ANOTHer
  337. 20K of memory away from you.
  338.  
  339. ESC.COM will save you from having to deal with most of the
  340. convolutions of PROMPT commands, and can be tried out from the
  341. keyboard without affecting anything else except what the codes
  342. are intended to affect.  Make sure that ESC.COM is in the current
  343. directory, and we'll play.  A couple of screen examples - from
  344. the DOS prompt, try the following command:
  345.  
  346.    DOSPROMPT>esc 4m<Enter>   (note the lowercase "m")
  347.  
  348. The lowercase "m" tells ANSI that the number is supposed to go to
  349. the screen ("m" for "monitor"?).  If you have a color monitor,
  350. you will now see blue characters on a black background.  A mono
  351. monitor will show the same old black and white (or amber), but
  352. the characters will now all be underlined.  do a DIR command and
  353. see what it looks like.
  354.  
  355. Okay, try this.  From the DOS prompt:
  356.  
  357.    DOSPROMPT>esc 5m<Enter>    (still note lowercase "m")
  358.  
  359. Now everything after the last command line should be blinking
  360. (color and mono monitor).  Do a DIR command.  EVERYthing will be
  361. blinking. blinking. blinking. blinking.  Okay, enough of that -
  362. what is the code for Stop Blinking?  Hmmm, nothing in the Table
  363. for that.  There's no 6 code listed, let's try that:
  364.  
  365.    DOSPROMPT>esc 6m<Enter>
  366.  
  367. Rats! - no change... how am I going to fix this?  Well, now for
  368. one of ANSI's little mysteries - there are not any codes for
  369. turning a lot of attributes off individually, such as blink, so
  370. you have to turn ALL attributes off, then turn on the ones you
  371. want to keep.  From the DOS prompt:
  372.  
  373.    DOSPROMPT>esc 0m<Enter>
  374.  
  375. Ahhh!  Normal screen again.  What else can we get?  Let's try
  376. this...
  377.  
  378.    DOSPROMPT>esc 33m<Enter>
  379.  
  380. Yellow Characters! Not bad... try another:
  381.  
  382.    DOSPROMPT>esc 44m<Enter>
  383.  
  384. Yellow characters on a blue background!  I could get to like
  385. this.  (Notice that the attributes are cumulative.  The
  386. foreground color was kept, and the background color was just
  387. added to the screen around it. try:
  388.  
  389.    DOSPROMPT>esc 37m<Enter>
  390.  
  391. White characters on a blue background.  Easy on the eyes.  What
  392. happens if I try this:
  393.  
  394.    DOSPROMPT>esc 34m<Enter>
  395.  
  396. Wait. Whoa! WHAT HAPPENED!!  I can't read ANYTHING now! - well,
  397. that's what happens when you run blue on blue.  It makes it a
  398. little tough to read the characters.  All is not lost, though. 
  399. Type (carefully) (you won't see this on the screen):
  400.  
  401.              esc 0m<Enter>
  402.  
  403. and you will be back to good old white on black.  This brings up
  404. a point, however.  Esc 0m is about the only way you have of
  405. resetting attributes.  Erase them all and start over.  Try the
  406. following codes:
  407.  
  408.    DOSPROMPT>esc 33;5;41m<Enter>
  409.  
  410. Yellow characters on a red background blinking blinking
  411. blinking...  This is a bit much - let's turn off the blinking,
  412. and keep the colors.  Type in the following command:
  413.  
  414.    DOSPROMPT>esc 0;33;41m<Enter>
  415.  
  416. Whew!  Much better.  Colors without the blinking.  A minor
  417. annoyance to have to reset the colors just to get rid of blinking
  418. or bright attributes, but the only things you have to restore are
  419. a foreground and a background color.
  420.  
  421. Put your favorites in a AUTOEXEC.BAT, and DOS will boot up in
  422. color! and stay that way, even after exiting a program back to
  423. DOS.  If the program is one of those that resets the screen
  424. attributes to 0, fix its wagon with a CLS command from DOS, and
  425. you will have your screen colors back.
  426.  
  427. Okay what's next?
  428.  
  429. Hey Bunky!  What's That?  You say that you have typed DIR /P so
  430. many times that you can't read the keytops anymore?  You say that
  431. you put the keyboard through the screen after misspelling
  432. CD\WAY\DOWN\DEEP\SUBDIRECTORY four times?  You say that you can't
  433. remember the syntax for that BACKUP command, and you keep sending
  434. your backup files to the printer?? Is that what's troubling you,
  435. Bunky???  Well, FEAR NOT, friends of the floppy persuasion, help
  436. is here, and it doesn't cost $49.95; it doesn't cost $39.95; it
  437. doesn't even cost $29.95; just sent $19.95 to... never mind, DOS
  438. will do it for free.  Watch this - from the DOS prompt:
  439.  
  440.    DOSPROMPT>esc 0;63;"dir/p";13p<Enter>
  441.  
  442. What!  Nothing happened!  (I hope not, anyway.)  Well what DID we
  443. do, then?  It goes like this...
  444.  
  445. "esc" is the escape program.
  446. "0"   is the extended ASCII code we sent ANSI for the keyboard.
  447. "63"  is the key code for the F5 key (check the table above).
  448. "dir/p" is the command we want the F5 key to pass to DOS.
  449. "13"  is the ASCII code for <Enter>.
  450. "p"   is the code to send the numbers to the keyboard routines.
  451.  
  452. Look at the command line syntax.  There is a space between "esc"
  453. and the first character, and there is a ";" between each of the
  454. elements.  Press the <F5> key and see what happens.  Wow! a one-
  455. key directory command!  (If nothing happens, check your command
  456. line entry for mistakes - remember the command line editor on F1
  457. through F4?  That's why we put the new command on F5.)  How about
  458. that thorny pathname that is so long?  Try this:
  459.  
  460.    DOSPROMPT>esc 0;64;"cd\way\deep\down\subdirectory";13p<Enter>
  461.  
  462. Press the <F6> key, and you should now be in that subdirectory.
  463.  
  464. How about that Backup command that you can never quite remember
  465. the syntax for?  Dig out the DOS manual, look up those command
  466. switches for the last time, and try this:
  467.  
  468.    DOSPROMPT>esc 0;113;"backup c:\subdir a:/s/d";13p<Enter>
  469.  
  470.  
  471. This puts the BACKUP command on the <ALT><F10> key, where you are
  472. not likely to press it accidentally.
  473.  
  474. I think you are getting the idea now, but let me leave you with a
  475. couple of things to avoid trouble.  Don't use <CTRL> <letter-key>
  476. combinations for reassignment.  Several of these are used by DOS
  477. for terminal commands (<CTRL><S>, <CTRL><Q>, <CTRL><C>, etc.) and
  478. used by many programs for the same functions, and programs may
  479. not operate correctly without these available the way DOS assigns
  480. them.  Not to overlook the obvious, don't reassign unshifted or
  481. shifted letter keys.  On the other hand, you might take a stab at
  482. creating your own Dvorak keyboard.
  483.  
  484. DOS assigns only 8 or so of the 40 possible function key
  485. combinations (the 10 function keys, and <CTRL> or <ALT> or <SHFT>
  486. plus the 10 function keys) so most of these are available, but
  487. take care not to reassign so many that you can't remember what
  488. they are.  A solution that is more complicated than the problem
  489. is not a solution.  I am using a scheme where the function key
  490. combinations are used for DOS commands, and the <ALT><letter-
  491. keys> are used for programs, i.e. <ALT><W> is WORDWIMP word
  492. processor, <ALT><L> is LIMPWIMP spreadsheet, <ALT><D> is DATAWIMP
  493. database.  As a farther example, you can put the word processor
  494. subdirectory in your PATH command so that you can run your word
  495. processor from any subdirectory, and what's more, you can run it
  496. with a single keypress combination!
  497.  
  498. ANSI is finally out of the closet for me.  The ESC.COM program
  499. makes it accessible with a minimum of fuss - just look up the
  500. codes that do what you want and send them to ANSI with ESC.COM. 
  501. Play with it from the keyboard, and put the codes you like in
  502. your AUTOEXEC.BAT file, so they are automatically installed when
  503. you start up your computer.  ESC.COM also works with FANSI,
  504. NANSI, and ZANSI, some common ANSI.SYS substitutes.  Don't let
  505. your wimpy keys push you around - push them back, and get more
  506. from them!
  507.  
  508.  
  509.                                       - Jan Fagerholm
  510.                                         PC Clubhouse
  511.                                         BBS (415) 581-8529
  512.                                         BBS II (415) 357-9577
  513.                                         Compuserve 75755,376
  514.                                         GEnie mail jfagerholm
  515.