home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_1.iso / msdos / infoprog / dosprog2.faq < prev    next >
Internet Message Format  |  1997-06-15  |  31KB

  1. Path: Eunet.yu!EU.net!news.mathworks.com!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!faqserv
  2. From: carlyle@tocnet.com (Jeffrey Carlyle)
  3. Newsgroups: comp.os.msdos.programmer,alt.msdos.programmer,comp.answers,news.answers
  4. Subject: comp.os.msdos.programmer FAQ part 2/5
  5. Supersedes: <msdos-programmer-faq/part2_840820372@rtfm.mit.edu>
  6. Followup-To: comp.os.msdos.programmer
  7. Date: 16 Sep 1996 08:25:21 GMT
  8. Organization: Stratoware
  9. Lines: 687
  10. Sender: carlyle@tocnet.com (Jeffrey Carlyle)
  11. Approved: news-answers-request@MIT.Edu
  12. Expires: 20 Oct 1996 07:39:43 GMT
  13. Message-ID: <msdos-programmer-faq/part2_842859583@rtfm.mit.edu>
  14. References: <msdos-programmer-faq/part1_842859583@rtfm.mit.edu>
  15. Reply-To: carlyle@tocnet.com (Jeffrey Carlyle)
  16. NNTP-Posting-Host: bloom-picayune.mit.edu
  17. Summary: Frequently asked questions by DOS programmers with tested answers.
  18. X-Last-Updated: 1996/03/30
  19. Originator: faqserv@bloom-picayune.MIT.EDU
  20. Xref: Eunet.yu comp.os.msdos.programmer:6031 comp.answers:1091
  21.  
  22. Archive-name: msdos-programmer-faq/part2
  23. Comp-os-msdos-programmer-archive-name: dos-faq-pt2.txt
  24. Posting-frequency: 20 days
  25. Last-modified: 20 Mar 1996
  26.  
  27. ------------------------------
  28.  
  29. Subject: comp.os.msdos.programmer FAQ part 2/5
  30.  
  31. This is part 2 of the frequently asked questions list for the newsgroup
  32. comp.os.msdos.programmer.
  33.  
  34. Part 2:
  35.   Section 3.  Compile and Link
  36.   Section 4.  Keyboard
  37.  
  38. ------------------------------
  39.  
  40. Subject: comp.os.msdos.programmer FAQ
  41.  
  42. comp.os.msdos.programmer FAQ Version 2.06
  43.  
  44. Copyright 1996 by Jeffrey Carlyle, Stratoware. All rights reserved. This
  45. article is not in the public domain, but it may be redistributed so long
  46. as this notice, the acknowledgments, and the information on obtaining the
  47. latest copy of this list are retained and no fee is charged. The code
  48. fragments may be used freely;  credit would be polite. This FAQ is not to
  49. be included in any static archive (e.g. CD-ROM or book); however, a pointer
  50. to the FAQ may be included.
  51.  
  52.  =============================
  53.  TABLE OF CONTENTS
  54.  =============================
  55.  
  56. Part 1:
  57.   Section 1.  General FAQ and Newsgroup Information
  58.   Section 2.  General Reference
  59. Part 2:
  60.   Section 3.  Compile and Link
  61.   Section 4.  Keyboard
  62. Part 3:
  63.   Section 5.  Disks and files
  64.   Section 6.  Serial ports (COM ports)
  65. Part 4:
  66.   Section 7.  Other hardware questions and problems
  67.   Section 8.  Other software questions and problems
  68. Part 5:
  69.   Section 9.  Downloading
  70.   Section 10. Vendors and products
  71.  
  72. ------------------------------
  73.  
  74. Subject: Section 3.  Compile and link
  75.  
  76.   <q:3.01> - What the heck is "DGROUP > 64K"?
  77.   <q:3.02> - How do I fix "automatic data segment exceeds 64K" or "stack
  78.              plus data exceed 64K"?
  79.   <q:3.03> - Will Borland C code and Microsoft C code link together? 
  80.   <q:3.04> - Why did my program bomb at run time with "floating point
  81.              formats not linked" or "floating point not loaded"?
  82.   <q:3.05> - How can I change the stack size in Borland's C compilers? 
  83.   <q:3.06> - What's the format of an .OBJ file? 
  84.   <q:3.07> - What's the format of an .EXE header?
  85.   <q:3.08> - What's the difference between .COM and .EXE formats?
  86.   <q:3.09> - How do I create a .COM file? 
  87.   <q:3.10> - Where is EXE2BIN located?
  88.   <q:3.11> - What does this message mean: "A20 already enabled so test
  89.              is meaning less?"
  90.  
  91. ------------------------------
  92.  
  93. Subject: <q:3.01> - What the heck is "DGROUP > 64K"?
  94.  
  95.     This Q explains the problem; the next Q gives some remedies.
  96.  
  97.     DGROUP is a link-time group of data segments, and the compiler
  98.     typically generates code that expects DS to be pointing to DGROUP.
  99.     (Exception:  Borland's huge model has no DGROUP.)
  100.  
  101.     Here's what goes into DGROUP:
  102.  
  103.     - tiny model (all pointers near):  DGROUP holds the entire program.
  104.  
  105.     - small and medium models (data pointers near):  DGROUP holds all
  106.       globals and static variables including string literals, plus the
  107.       stack and the heap.
  108.  
  109.     - large, compact, and huge models in Microsoft (data pointers far):
  110.       DGROUP holds only initialized globals and static variables
  111.       including string literals, plus the stack and the near heap.
  112.  
  113.     - large and compact models in Borland (data pointers far): DGROUP
  114.       holds initialized and uninitialized globals and static variables
  115.       including string literals, but not the stack or heap.
  116.  
  117.     - huge model in Borland (data pointers far): there is no DGROUP, so
  118.       the 64K limit doesn't apply.
  119.  
  120.     In all of the above, which is to say all six models in Microsoft C
  121.     and all but huge in Borland C, DGROUP is limited to 64K including
  122.     string literals (which are treated as static data).  This limitation
  123.     is due to the Intel CPU's segmented architecture.
  124.  
  125.     For more information, see topics like "memory models" and "memory
  126.     management" in the index of your compiler manual.  Also see
  127.     TI738.asc, downloadable as part of
  128.  
  129.         <ftp://oak.oakland.edu/pub/msdos/turbo-c/bchelp10.zip>
  130.         <ftp://garbo.uwasa.fi/pc/turbopas/bchelp10.zip>
  131.  
  132.     for an extended general discussion of memory usage in Borland C
  133.     programs, of which much applies to any C compiler in DOS.
  134.  
  135. ------------------------------
  136.  
  137. Subject: <q:3.02> - How do I fix "automatic data segment exceeds 64K" or
  138.         "stack plus data exceed 64K"?
  139.  
  140.     These messages are a variation of "DGROUP > 64K".  For causes,
  141.     please see the preceding Q.
  142.  
  143.     If you get this error in tiny model, your program is simply too big
  144.     and you must use a different memory model.  If you get this link
  145.     error in models S, C, M, L, or Microsoft's H, there are some things
  146.     you can do.  (This error can't occur in Borland's huge model.)
  147.  
  148.     If you have one or two big global arrays, simply declare them far.
  149.     The compiler takes this to mean that any references to them will use
  150.     32-bit pointers, so they'll be in separate segments and no longer
  151.     part of DGROUP.
  152.  
  153.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  154.     with Borland C++ 2.0 and up.  This will automatically put variables
  155.     above a certain size into their own segments outside of DGROUP.
  156.  
  157.     Yet another option is to change global arrays to far pointers.  Then
  158.     at the beginning of your program, allocate them from the far heap
  159.     (_fmalloc() in Microsoft, farmalloc() in Borland).
  160.  
  161.     Finally, you can change to huge model (with Borland compilers, not
  162.     Microsoft).  Borland's H model still uses far pointers by default,
  163.     but "sets aside the [64K] limit" and has no DGROUP group, according
  164.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  165.     huge data pointers by default but retains DGROUP and its 64K limit,
  166.     so switching to the H model doesn't buy you anything if you have
  167.     DGROUP problems.
  168.  
  169. ------------------------------
  170.  
  171. Subject: <q:3.03> - Will Borland C code and Microsoft C code link together?
  172.  
  173.     Typically this question is asked by someone who owns compiler A and
  174.     is trying to write code to link with a third-party library that was
  175.     compiled under compiler B.
  176.  
  177.     The answer to the question is, Not in general.  Here are some of the
  178.     reasons:
  179.  
  180.     - "Helper" functions (undocumented functions for stack checking,
  181.       floating-point arithmetic, and operations on longs) differ between
  182.       the two compilers.
  183.  
  184.     - Extended dictionaries are not compatable between the 2 formats.
  185.       However, the basic structure of both MS and Borland OBJ formats
  186.       is based on the OMF format so specifing that the linker ignore
  187.       the extended dictionary records (/NOE for LINK, -e for TLINK)
  188.       will disable this little hassel.
  189.  
  190.     - The compilers may embed instructions in the object code that tell
  191.       the linker to look for their own run-time libraries.  You can use
  192.       the linker option that says to ignore such instructions: /n in
  193.       TLINK, /NOD in the Microsoft linker (the one that comes with the C
  194.       compiler, not the one that used to come with DOS).  But getting
  195.       around this problem will very likely just reveal other problems,
  196.       like different helper functions, that have no easy solution.
  197.  
  198.     Those problems will generate link-time errors.  Others may not show
  199.     up until run time:
  200.  
  201.     - Borland's compact, large, and huge models don't assume DS=SS, but
  202.       Microsoft's do.  The -Fs option on the Borland compiler, or one of
  203.       the /A options on Microsoft, should take care of this problem--
  204.       once you know that's what's going on.
  205.  
  206.     - Check conventions for ordering and packing structure members, and
  207.       for alignment of various types on byte, word, paragraph, or other
  208.       boundaries.  Again, you can generally adjust your code to match if
  209.       you know what conventions were used in compiling the "foreign"
  210.       libraries.
  211.  
  212.     - Check the obvious and make sure that your code was compiled under
  213.       the same memory model as the code you're trying to link with.
  214.       (That's necessary, but no guarantee.  Microsoft and Borland don't
  215.       use exactly the same conventions for segments and groups,
  216.       particularly in the larger memory models.)
  217.  
  218.     That said, there are some circumstances where you can link hybrids.
  219.     Your best chance of success comes if you compile in large model with
  220.     the compiler switch that says to reload DS on entry to each
  221.     function, avoid longs and floating point, use only 16-bit pointers,
  222.     suppress stack checking, and specify all libraries used in the link.
  223.  
  224. ------------------------------
  225.  
  226. Subject: <q:3.04> - Why did my program bomb at run time with "floating
  227.         point formats not linked" or "floating point not loaded"?
  228.  
  229.     These messages look similar but have very different causes.
  230.  
  231.     "floating point not loaded" is Microsoft C's run-time message when
  232.     the code requires a numeric coprocessor but your computer doesn't
  233.     have one installed.  If the program is yours, relink it using the
  234.     xLIBCE or xLIBCA library (where x is the memory model).
  235.  
  236.     "floating point formats not linked" is a Borland run-time error
  237.     (Borland C or C++, Turbo C or C++).  Borland's compilers try to be
  238.     smart and not link in the floating-point (f-p) library unless you
  239.     need it.  Alas, they all get the decision wrong.  One common case is
  240.     where you don't call any f-p functions, but you have %f or other f-p
  241.     formats in scanf() or printf() calls.  The cure is to call an f-p
  242.     function, or at least force one to be present in the link.
  243.  
  244.     To do that, define this function somewhere in a source file but
  245.     don't call it:
  246.  
  247.         static void forcefloat(float *p) {
  248.             float f = *p;
  249.             forcefloat(&f);
  250.         }
  251.  
  252.     It doesn't have to be in the module with the main program, as long
  253.     as it's in a module that will be included in the link.
  254.  
  255.     If you have Borland C++ 3.0, the README file documents a slightly
  256.     less ugly work-around.  Insert these statements in your program:
  257.  
  258.         extern unsigned _floatconvert;
  259.         #pragma extref _floatconvert
  260.  
  261. ------------------------------
  262.  
  263. Subject: <q:3.05> - How can I change the stack size in Borland's C
  264.         compilers?
  265.  
  266.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  267.     size" in the index but the global variable _stklen should be there.
  268.     The manual will instruct you to put a statement like
  269.  
  270.         extern unsigned _stklen = 54321U;
  271.  
  272.     in your code, outside of any function.  You must assign the value
  273.     right in the extern statement; it won't work to assign a value at
  274.     run time.  The linker may give you a duplicate symbol warning, which
  275.     you can ignore.
  276.  
  277.     If you are using the Borland PowerPAck for DOS _stklen does not
  278.     change the stack size. To change the stack size you must use STACKSIZE
  279.     in your .DEF file. HEAPSIZE can be used to change the size of your
  280.     program's heap.
  281.  
  282. ------------------------------
  283.  
  284. Subject: <q:3.06> - What's the format of an .OBJ file? 
  285. Date: Wed, 11 Jan 95 15:34:00 CDT
  286.  
  287.     - base .OBJ format:  Intel's document number #121748-001, {8086
  288.       Relocatable Object Module Formats}.  (not verified)
  289.  
  290.     Both Microsoft and Borland have extended the .OBJ format, as has IBM
  291.     for OS/2; and according to the MS-DOS encyclopedia, Microsoft
  292.     doesn't actually use all the listed formats.
  293.  
  294.     - Microsoft-specific .OBJ formats:
  295.  
  296.       * The .OBJ format document in a text file format, is downloadable
  297.       as <ftp://ftp.microsoft.com/softlib/mslfiles/ss0288.exe>
  298.  
  299.       * A 45-page article can be found in the {MS-DOS Encyclopedia},
  300.         ISBN 1-55615-049-0, now out of print.
  301.  
  302.       * "Microsoft Object Module Format (OMF)" Specification, 22 Nov
  303.         1991, was published by the Microsoft Languages Group.  (not
  304.         verified)
  305.  
  306.     - Borland-specific .OBJ formats:  Open Architecture Handbook.  The
  307.       Borland Developer's Technical Guide, 1991, no ISBN.  Chapter 2,
  308.       "Object file contents", (pages 27-50) covers the comment records
  309.       sent to the object file by Borland C++ version 3.0 and other
  310.       Borland compilers.  The comment records mostly contain information
  311.       for the Borland debugger. (not verified)
  312.  
  313.     - A "tutorial on the .OBJ format" comes with the VAL experimental
  314.       linker, downloadable as
  315.  
  316.         <ftp://oak.oakland.edu/pub/msdos/pgmutil/val-link.zip>
  317.         <ftp://garbo.uwasa.fi/pc/assembler/linker.zoo>
  318.  
  319.       Despite such different names, those files have the same contents,
  320.       but their contents are dated 18 Feb 1989.  You'd be better off
  321.       with one of the more recent references listed above.
  322.  
  323. ------------------------------
  324.  
  325. Subject: <q:3.07> - What's the format of an .EXE header?
  326.  
  327.     See PC Magazine 30 June 1992 (xi:12) pages 349-350 for the old and
  328.     new formats.  For a more detailed layout, look under INT 21 AH=4B in
  329.     Ralf Brown's interrupt list <q:2.03>.  That list includes extensions
  330.     for Borland's TLINK and Borland debugger info.
  331.  
  332.     Among the books that detail formats of executable files are {DOS
  333.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  334.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  335.     ISBN 1-55615-329-5.
  336.  
  337. ------------------------------
  338.  
  339. Subject: <q:3.08> - What's the difference between .COM and .EXE formats?
  340.  
  341.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  342.     file will undergo some further relocation when it is run (and so it
  343.     begins with a relocation header).  A .COM file is limited to 64K for
  344.     all segments combined, but an .EXE file can have as many segments as
  345.     your linker will handle and be as large as RAM can take.
  346.  
  347.     The actual file extension doesn't matter.  DOS knows that a file
  348.     being loaded is in .EXE format if its first two bytes are MZ or ZM;
  349.     otherwise it is assumed to be in .COM format.  For instance, DR-DOS
  350.     6.0's COMMAND.COM is in .EXE format.
  351.  
  352. ------------------------------
  353.  
  354. Subject: <q:3.09> - How do I create a .COM file? 
  355. Date: Fri, 13 Jan 95 15:34:00 CDT
  356.  
  357.    There are two steps to creating a .COM file. First, your program must
  358.    not have a stack. In C, you must compile your program with the TINY
  359.    memory model. Second, use EXE2BIN or a similiar program to convert
  360.    the .EXE file to a .COM file. To find EXE2BIN see subject: <q:3.10>
  361.    "Where is EXE2BIN located?"
  362.  
  363. ------------------------------
  364.  
  365. Subject: <q:3.10> - Where is EXE2BIN located? 
  366. Date: Fri, 07 Jul 95 15:34:00 CDT
  367.  
  368.    EXE2BIN was formerly shipped with MS-DOS. If you are still using DOS
  369.    5.0 or earlier you can find EXE2BIN in your DOS directory. Users of
  370.    DOS 6.x need to get the MS-DOS Supplemental Disks. These disks are
  371.    available via FTP at ftp.microsoft.com.
  372.  
  373.    <ftp://ftp.microsoft.com/peropsys/msdos/public/supplmnt>
  374.  
  375. ------------------------------
  376.  
  377. Subject: <q:3.11> - hat does this message mean: "A20 already enabled so
  378.         test is meaning less?"
  379.  
  380.    This message is generated by the DPMIINST program included with older
  381.    versions of Borland C++ and Turbo C++ compilers. Before running
  382.    DPMIINST you must clean boot your computer.
  383.  
  384. ------------------------------
  385.  
  386. Subject: Section 4.  Keyboard
  387.  
  388.   <q:4.01> - How can I read a character without echoing it to the screen,
  389.              and without waiting for the user to press the Enter key?
  390.   <q:4.02> - How can I find out whether a character has been typed, without
  391.              waiting for one?
  392.   <q:4.03> - How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  393.   <q:4.04> - How can I disable the print screen function?
  394.   <q:4.05> - How can my program turn NumLock (CapsLock, ScrollLock) on or
  395.              off?
  396.   <q:4.06> - How can I speed up the keyboard's auto-repeat?
  397.   <q:4.07> - What is the SysRq key for?
  398.   <q:4.08> - How can my program tell what kind of keyboard is on the
  399.              system?
  400.   <q:4.09> - How can I tell if input, output, or stderr has been
  401.              redirected?
  402.   <q:4.10> - How can I increase the size of the keyboard buffer? 
  403.   <q:4.11> - How can I stuff characters into the keyboard buffer?
  404.  
  405. ------------------------------
  406.  
  407. Subject: <q:4.01> - How can I read a character without echoing it to the
  408.         screen, and without waiting for the user to press the Enter key?
  409.  
  410.     The C compilers from Microsoft and Borland offer getch() (or
  411.     getche() to echo the character); Turbo Pascal has ReadKey.
  412.  
  413.     In other programming languages, execute INT 21 AH=8; AL is returned
  414.     with the character from standard input (possibly redirected).  If
  415.     you don't want to allow redirection, or you want to capture Ctrl-C
  416.     and other special keys, use INT 16 AH=10; this will return the scan
  417.     code in AH and ASCII code (if possible) in AL, but  AL=E0 with AH
  418.     nonzero indicates that one of the grey "extended" keys was pressed.
  419.     (If your BIOS doesn't support the extended keyboard, use INT 16 AH=0
  420.     not 10.)
  421.  
  422. ------------------------------
  423.  
  424. Subject: <q:4.02> - How can I find out whether a character has been typed,
  425.         without waiting for one?
  426.  
  427.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  428.     the kbhit() function.  All of these tell you whether a key has been
  429.     pressed.  If no key has been pressed, they return that information
  430.     to your program.  If a keystroke is waiting, they tell your program
  431.     that but leave the key in the input buffer.
  432.  
  433.     You can use the BIOS call, INT 16 AH=01 or 11, to check whether an
  434.     actual keystroke is waiting; or the DOS call, INT 21 AH=0B, to check
  435.     for a keystroke from stdin (subject to redirection).  See Ralf
  436.     Brown's interrupt list <q:2.03>.
  437.  
  438. ------------------------------
  439.  
  440. Subject: <q:4.03> - How can I disable Ctrl-C/Ctrl-Break and/or
  441.         Ctrl-Alt-Del?
  442.  
  443.     Several utilities are downloadable from /pub/msdos/keyboard at
  444.     SimTel.  In that directory, cadel.zip contains a TSR (with source
  445.     code) to disable those keys.  Also, keykill.arc contains two
  446.     utilities:  keykill.com lets you disable up to three keys of your
  447.     choice, and deboot.com changes the boot key to leftShift-Alt-Del.
  448.  
  449.     C programmers who simply want to make sure that the user can't Ctrl-
  450.     Break out of their program can use the ANSI-standard signal()
  451.     function; the Borland compilers also offer ctrlbrk() for handling
  452.     Ctrl-Break.  However, if your program uses normal DOS input such as
  453.     getch(), ^C will appear on the screen when the user presses Ctrl-C
  454.     or Ctrl-Break.  You can avoid the ^C echo for Ctrl-C by using
  455.     _bios_keybrd() in MSC or bioskey() in BC++; however, Ctrl-Break will
  456.     still terminate the program.
  457.  
  458.     An alternative approach involves programming input at a lower level.
  459.     You can use INT 21 AH=7, which allows redirection but doesn't echo
  460.     the ^C (or any other character, for that matter); or use INT 16 AH=0
  461.     or 10; or hook INT 9 to discard Ctrl-C and Ctrl-Break before the
  462.     regular BIOS keyboard handler sees them; etc., etc.
  463.  
  464.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  465.     differently internally.  Ctrl-Break, like all keystrokes, is
  466.     processed by the BIOS code at INT 9 as soon as the user presses the
  467.     keys, even if earlier keys are still in the keyboard buffer:  by
  468.     default the handler at INT 1B is called.  Ctrl-C is not special to
  469.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  470.     special to DOS functions 1 and 8 when at the head of the keyboard
  471.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  472.     polling the keyboard for Ctrl-C during non-keyboard operations.
  473.  
  474.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  475.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  476.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  477.     the IBM PC}, ISBN 0-942386-92-2.
  478.  
  479. ------------------------------
  480.  
  481. Subject: <q:4.04> - How can I disable the print screen function?
  482.  
  483.     There are really two print screen functions:  1) print current
  484.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or Shift-
  485.     grey*, and 2) turn on continuous screen echo, started and stopped by
  486.     Ctrl-P or Ctrl-PrtSc.
  487.  
  488.     1) Screen snapshot to printer
  489.  
  490.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  491.     with that interrupt handler.  The standard handler, in BIOS versions
  492.     dated December 1982 or later, uses a byte at 0040:0100 (= 0000:0500)
  493.     to determine whether a print screen is currently in progress.  If it
  494.     is, pressing PrintScreen again is ignored.  So to disable the screen
  495.     snapshot, all you have to do is write a 1 to that byte.  When the
  496.     user presses PrintScreen, the BIOS will think that a print screen is
  497.     already in progress and will ignore the user's keypress.  You can re-
  498.     enable PrintScreen by zeroing the same byte.
  499.  
  500.     Here's some simple code:
  501.  
  502.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  503.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  504.             *flag = (unsigned char)!allow;
  505.         }
  506.  
  507.     2) Continuous echo of screen to printer
  508.  
  509.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  510.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  511.     "printing" strings like these to the screen (BASIC print, C
  512.     printf(), Pascal Write statements, or ECHO command in batch files),
  513.     where <27> stands for the Escape character, ASCII 27:
  514.  
  515.         <27>[0;114;"Ctrl-PrtSc disabled"p
  516.         <27>[16;"^P"p
  517.  
  518.     If you haven't installed ANSI.SYS, I can't offer an easy way to
  519.     disable the echo-screen-to-printer function.
  520.  
  521.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  522.     your only concern is not locking up your machine, when you see the
  523.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  524.     press I.  As an alternative, install one of the many print spoolers
  525.     that intercept printer-status queries and always return "Printer
  526.     ready".
  527.  
  528. ------------------------------
  529.  
  530. Subject: <q:4.05> - How can my program turn NumLock (CapsLock, ScrollLock)
  531.         on or off?
  532.  
  533.     First, if you just don't want NumLock turned on when you reboot,
  534.     check your system's setups.  (Use Ctrl-Alt-Enter any time, or press
  535.     a special key like Del at boot time, or run the setup program
  536.     supplied with your system.)  Many systems now have an option in
  537.     setup to turn NumLock off at boot time.
  538.  
  539.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  540.     some code:  lck() turns on a lock state, and unlck() turns it off.
  541.     (The status lights on some keyboards may not reflect the change.  If
  542.     yours is one, call INT 16 AH=2, "get shift status", and that may
  543.     update them.  It will certainly do no harm.)
  544.  
  545.         #define NUM_LOCK  (1 << 5)
  546.         #define CAPS_LOCK (1 << 6)
  547.         #define SCRL_LOCK (1 << 4)
  548.         void lck(int shiftype) {
  549.             char far* kbdstatus = (char far*)0x00400017UL;
  550.             *kbdstatus |= (char)shiftype;
  551.         }
  552.         void unlck(int shiftype) {
  553.             char far* kbdstatus = (char far*)0x00400017UL;
  554.             *kbdstatus &= ~(char)shiftype;
  555.         }
  556.  
  557. ------------------------------
  558.  
  559. Subject: <q:4.06> - How can I speed up the keyboard's auto-repeat?
  560.  
  561.     The keyboard speed has two components: delay (before a key that you
  562.     hold down starts repeating) and typematic rate (the speed once the
  563.     key starts repeating).  Most BIOS versions since 1986 let software
  564.     change the delay and typematic rate by calling INT 16 AH=3, "set
  565.     typematic rate and delay"; see Ralf Brown's interrupt list (Q 1.17).
  566.     If you have DOS 4.0 or later, you can use the MODE CON command that
  567.     you'll find in your DOS manual.
  568.  
  569.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  570.     easily be changed.  According to PC Magazine 15 Jan 1991 (x:1) page
  571.     409, to adjust the typematic rate you need "a memory-resident
  572.     program which simply '[watches]' the keyboard to see if you're
  573.     holding down a key ... and after a certain time [starts] stuffing
  574.     extra copies of the held-down key into the buffer."  No source code
  575.     is given in that issue; but the QUICKEYS utility that PC Magazine
  576.     published in 1986 does this sort of watching (not verified); source
  577.     and object code are downloadable in
  578.  
  579.     <ftp://oak.oakland.edu/pub/msdos/pcmag/vol5n05.zip>
  580.  
  581. ------------------------------
  582.  
  583. Subject: <q:4.07> - What is the SysRq key for?
  584.  
  585.     There is no standard use for the key.  The BIOS keyboard routines in
  586.     INT 16 simply ignore it; therefore so do the DOS input routines in
  587.     INT 21 as well as the keyboard routines in libraries supplied with
  588.     high-level languages.
  589.  
  590.     When you press or release a key, the keyboard triggers hardware line
  591.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  592.     keyboard and the shift states from the BIOS data area.
  593.  
  594.     What happens next depends on whether your PC's BIOS supports an
  595.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  596.     AH=4F to translate the scan code.  If the translated scan code is 54
  597.     hex (for the SysRq key) then INT 9 calls INT 15 AH=85 and doesn't
  598.     put the keystroke into the keyboard buffer.  The default handler of
  599.     that function does nothing and simply returns.  (If your PC has an
  600.     older BIOS that doesn't support the extended keyboards, INT 15 AH=4F
  601.     is not called.  Early ATs have 84-key keyboards, so their BIOS calls
  602.     INT 15 AH=85 but not 4F.)
  603.  
  604.     Thus your program is free to use SysRq for its own purposes, but at
  605.     the cost of some programming.  You could hook INT 9, but it's
  606.     probably easier to hook INT 15 AH=85, which is called when SysRq is
  607.     pressed or released.
  608.  
  609. ------------------------------
  610.  
  611. Subject: <q:4.08> - How can my program tell what kind of keyboard is on
  612.         the system?
  613.  
  614.     Ralf Brown's Interrupt List <q:2.03> includes MEMORY.LST, a detailed
  615.     breakdown by Robin Walker of the contents of the BIOS system block
  616.     that starts at 0040:0000.  Bit 4 of byte 0040:0096 is "1=enhanced
  617.     keyboard installed".  C code to test the keyboard type:
  618.  
  619.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  620.         if (0x10 & *kbd_stat_byte3)
  621.             /* 101- or 102-key keyboard is installed */
  622.  
  623.     PC Magazine 15 Jan 1991 (x:1) suggests on page 412 that "for some
  624.     clones [the above test] is not foolproof".  If you use this method
  625.     in your program you should provide the user some way to override
  626.     this test, or at least some way to tell your program to assume a non-
  627.     enhanced keyboard.  The article suggests a different approach to
  628.     determining the type of keyboard.
  629.  
  630. ------------------------------
  631.  
  632. Subject: <q:4.09> - How can I tell if input, output, or stderr has
  633.         been redirected? 
  634. Date: Tue, 7 Mar 95 12:00:00 CDT
  635.  
  636.  
  637.     Normally, input and output are associated with the console (i.e.,
  638.     with the keyboard and the screen, respectively).  If either is not,
  639.     you know that it has been redirected.  Some source code to check
  640.     this is available at the usual archive sites.
  641.  
  642.     If you program in Turbo Pascal, you'll want this downloadable
  643.     collection of Turbo Pascal units:
  644.  
  645.     <ftp://garbo.uwasa.fi/pc/ts/tspa33*.zip>
  646.     <ftp://oak.oakland.edu/pub/msdos/turbopas/tspa33*.zip>
  647.  
  648.     (where the * is 70, 60, 55, 50, or 40 for Turbo Pascal 7.0, 6.0,
  649.     5.5, 5.0, or 4.0 respectively.)  Source code is not included.  Also
  650.     see the downloadable Frequently Asked Questions files by Timo Salmi:
  651.  
  652.     <ftp://garbo.uwasa.fi/pc/ts/tsfaqp*.zip>
  653.     <ftp://oak.oakland.edu/pub/msdos/info/tsfaqp*.zip>
  654.  
  655.     If you program in C, use isatty() if your implementation has it.
  656.     Otherwise,
  657.  
  658.     <ftp://oak.oakland.edu/pub/msdos/sysutil/is_con10.zip>
  659.  
  660.     is downloadable from SimTel; it includes source code.
  661.  
  662.     Good references for the principles are PC Magazine 16 Apr 1991 (x:7)
  663.     page 374; Ray Duncan's {Advanced MS-DOS}, ISBN 1-55615-157-8, or
  664.     Ralf Brown's interrupt list (<q:2.03>) for INT 21 AX=4400; and Terry
  665.     Dettman and Jim Kyle's {DOS Programmer's Reference: 2d edition},
  666.     ISBN 0-88022-458-4, pages 602-603.
  667.  
  668. ------------------------------
  669.  
  670. Subject: <q:4.10> - How can I increase the size of the keyboard buffer?
  671. Date: Fri, 07 Jul 95 15:34:00 CDT
  672.  
  673.  
  674.     Microsoft has its own keyboard extender availible on the MS-DOS
  675.     supplmental disks for MS-DOS 6.22. 
  676.  
  677.     <ftp://ftp.microsoft.com/peropsys/msdos/public/supplmnt/sup622.exe>
  678.  
  679.     I tested only one of the many available device drivers that do this,
  680.     namely BUF160, which extends the keyboard buffer to 160 characters.
  681.     It performed flawlessly for two years with MS-DOS 5 and Windows 3.1.
  682.     It's downloadable as
  683.  
  684.     <ftp://oak.oakland.edu/pub/msdos/keyboard/buf160_6.zip>
  685.     <ftp://garbo.uwasa.fi/pc/keyboard/buf160_6.zip>
  686.  
  687. ------------------------------
  688.  
  689. Subject: <q:4.11> - How can I stuff characters into the keyboard buffer?
  690.  
  691.     If your computer has an enhanced keyboard (see <q:4.08> - "How can my
  692.     program tell what kind of keyboard is on the system?"), put the scan
  693.     code in CH and the ASCII character in CL, then execute INT 16 AH=5.
  694.     The return in AL is 0 for success or 1 for buffer full.
  695.  
  696. ------------------------------
  697.  
  698. Subject: End
  699.  
  700. (End of comp.os.msdos.programmer FAQ Version 2.06 Part 2/5)
  701. (This text is copyright 1996 by Jeffrey Carlyle. All rights reserved.)
  702.  
  703.  
  704. // Jeffrey Carlyle, Stratoware, Bowling Green, KY USA _,,-^`--. 
  705. // comp.os.msdos.programmer FAQ maintainer      .__,-'         \
  706. // <mailto:carlyle@tocnet.com>                _/     *        ,/
  707. // <http://users.aol.com/jc101>              (__,-----------''
  708.  
  709.