home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10652 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  26.6 KB

  1. Xref: sparky comp.os.msdos.programmer:10652 news.answers:4001
  2. Newsgroups: comp.os.msdos.programmer,news.answers
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!ncoast!brown
  4. From: brown@NCoast.ORG (Stan Brown)
  5. Subject: comp.os.msdos.programmer FAQ part 2 of 4
  6. Expires: Wed, 30 Dec 1992 17:49:54 GMT
  7. Organization: Oak Road Systems, Cleveland Ohio USA
  8. Date: Sun, 15 Nov 1992 17:49:54 GMT
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <msdos-faq.921115.2@NCoast.ORG>
  11. Followup-To: comp.os.msdos.programmer
  12. References: <msdos-faq.921115.1@NCoast.ORG>
  13. Supersedes: <msdos-faq.921020.2@NCoast.ORG>
  14. Lines: 558
  15.  
  16. Archive-name: msdos-programmer-faq/part2
  17. Last-modified: 15 November 1922
  18.  
  19. (continued from part 1)         (no warranty on the code or information)
  20.  
  21. If the posting date is more than six weeks in the past, see instructions
  22. at the end of this article for how to get an updated copy.
  23.  
  24.             Copyright (C) 1992  Stan Brown, Oak Road Systems
  25.  
  26.  
  27. section 1. General questions
  28. ============================
  29.  
  30. Q101. Why won't my code work?
  31.  
  32.     First you need to try to determine whether the problem is in your
  33.     use of the programming language or in your use of MSDOS and your PC
  34.     hardware.  (Your manual should tell you which features are standard
  35.     and which are vendor- or MSDOS- or PC-specific.  You _have_ read
  36.     your manual carefully, haven't you?)
  37.  
  38.     If the feature that seems to be working wrong is something related
  39.     to your PC hardware or to the internals of MS-DOS, this group is the
  40.     right place to ask.  (Please check this list first, to make sure
  41.     your question isn't already answered.)
  42.  
  43.     On the other hand, if your problem is with the programming language,
  44.     the comp.lang hierarchy (including comp.lang.pascal and comp.lang c)
  45.     is probably a better resource.  Please read the other group's FAQ
  46.     list thoroughly before posting.  (These exist in comp.lang.c,
  47.     comp.lang.c++, comp.lang.modula3, comp.lang.lisp, comp.lang.perl;
  48.     they may exist in other groups as well.)  It's almost never a good
  49.     idea to crosspost between this group and a language group.
  50.  
  51.     Before posting in either place, try to make your program as small as
  52.     possible while still exhibiting the bad behavior.  Sometimes this
  53.     alone is enough to show you where the trouble is.  Also edit your
  54.     description of the problem to be as short as possible.  This makes
  55.     it look more like you tried to solve the problem on your own, and
  56.     makes people more inclined to try to help you.
  57.  
  58.     When you do post a question, it's good manners to say "email please;
  59.     I'll post a summary."  Then everybody else in the group doesn't have
  60.     to read ten virtually identical responses.  Of course, then you have
  61.     to follow through.  A summary is not simply pasting together all the
  62.     email you received.  Instead, write your own (brief) description of
  63.     the solution:  this is the best way to make sure you really
  64.     understand it.  Definitely don't repost people's cute signatures.
  65.  
  66. Q102. What is this newsgroup about?
  67.  
  68.     comp.os.msdos.programmer (comp.sys.ibm.pc.programmer until September
  69.     1990) concerns programming for MS-DOS systems.  The article "USENET
  70.     Readership report for Oct 92" in news.lists shows 40,000 readers of
  71.     this newsgroup worldwide.
  72.  
  73.     Much of our traffic is about language products (chiefly from Borland
  74.     and Microsoft).  More programming topics focus on C than on any one
  75.     other language.
  76.  
  77.     Since most MS-DOS systems run on hardware that is roughly compatible
  78.     with the IBM PC, on Intel 8088, 80188, or 80x86 chips, we tend to
  79.     get a lot of questions and answers about programming other parts of
  80.     the hardware.
  81.  
  82. Q103. What's the difference from comp.sys.ibm.pc.programmer?
  83.  
  84.     c.s.i.p.programmer is the old name of comp.os.msdos.programmer, and
  85.     has been obsolete since September 1990.  However, many systems have
  86.     not removed the old group, or have removed it but aliased it to the
  87.     new name.  This means that some people still think they're posting
  88.     to c.s.i.p.programmer even though they're actually posting to
  89.     c.o.m.programmer.
  90.  
  91.     You can easily verify the non-existence of c.s.i.p.programmer by
  92.     reference to the "List of Active Newsgroups" posted to news.groups.
  93.     It's available as /pub/usenet/news.answers/active-newsgroups/part1
  94.     from the archives (see "Where are FAQ lists archived?" in section C,
  95.     "More information").
  96.  
  97. Q104. What other newsgroups should I know about?
  98.  
  99.     Your best bet is to read the periodic information postings in the
  100.     comp.binaries.ibm.pc newsgroup.  Specially helpful articles:
  101.         Using the comp.binaries.ibm.pc.d groups
  102.         Beginner's guide to binaries
  103.         Starter kit
  104.         About archives and archivers
  105.     Please wait for these articles to come around; don't post a request.
  106.  
  107.     Also check out news.announce.newusers, even if you're not a new
  108.     user.  You may be surprised how much useful information is in the
  109.     monthly postings there.  Lots of old-timers also get useful stuff
  110.     from news.newusers.questions, especially the periodic postings.
  111.  
  112.     Remember that it's good manners to subscribe to any newsgroup and
  113.     read it for a while before you post a question.  When you post, it's
  114.     also good manners to ask for replies to be emailed and then to post
  115.     a summary, which you've edited down to the absolute minimum size.
  116.  
  117.     You may also be interested in the following newsgroups.  Caution:
  118.     Some of them have specialized charters; you'll probably get (and
  119.     deserve) some flames if you post to an inappropriate group.
  120.  
  121.     - misc.forsale.computers and misc.forsale.computers.pc-clone are
  122.       where you post notices of equipment, software, or computer books
  123.       that you want to sell.  Please don't post or crosspost those
  124.       notices here.
  125.  
  126.     - comp.os.ms-windows.programmer.tools and ...misc (formerly part of
  127.       comp.windows.ms.programmer):  Similar to this group, but focus
  128.       on programming for the MS-Windows platform.
  129.  
  130.     - comp.sys.ibm.pc.hardware is for more hardware-oriented discussions
  131.       of the machines that run DOS.
  132.  
  133.     - comp.binaries.ibm.pc.wanted: AFTER you have looked in the other
  134.       groups, this is the place to post a request for a particular
  135.       binary program.
  136.  
  137.     - comp.binaries.ibm.pc.archives used to explain how to use the
  138.       archive sites, especially garbo and Simtel; but the archive
  139.       managers have stopped posting notices of uploads.  There is a vote
  140.       (through 7 December 1992) on creating a moderated group,
  141.       comp.archives.msdos.announce, to replace it.  In the meantime, you
  142.       can subscribe to upload announcements by sending mail containing
  143.       the text line "subscribe msdos-ann" and no signature to
  144.       listserv@tacom-emh1.army.mil.
  145.  
  146.     - comp.binaries.ibm.pc.d is for discussions about programs posted in
  147.       comp.binaries.ibm.pc, and only those programs.  This is a good
  148.       place to report bugs in the programs, but not to ask where to find
  149.       them (see cbip.wanted, above).  cbip.d is NOT supposed to be a
  150.       general PC discussion group.
  151.  
  152.     - comp.sources.misc: a moderated group for source code for many
  153.       computer systems.  It tends to get lots of Unix stuff, but you may
  154.       also pick up some DOS-compatible code here.
  155.  
  156.     - alt.sources: an unmoderated group for source code.  Guidelines are
  157.       posted periodically.
  158.  
  159.  
  160. section 2. Compile and link
  161. ===========================
  162.  
  163. Q201. What the heck is "DGROUP > 64K"?
  164.  
  165.     DGROUP is a link-time group of data segments, and the compiler
  166.     typically generates code that expects DS to be pointing to DGROUP.
  167.     (Exception: Borland's huge model has no DGROUP.)
  168.  
  169.     Here's what goes into DGROUP:
  170.  
  171.     - tiny model (all pointers near):  DGROUP holds the entire program.
  172.  
  173.     - small and medium models (data pointers near):  DGROUP holds all
  174.       globals and static variables including string literals, plus the
  175.       stack and the heap.
  176.  
  177.     - large, compact, and huge models in Microsoft (data pointers far):
  178.       DGROUP holds only initialized globals and static variables
  179.       including string literals, plus the stack and the near heap.
  180.  
  181.     - large and compact models in Borland (data pointers far): DGROUP
  182.       holds initialized and uninitialized globals and static variables
  183.       including string literals, but not the stack or heap.
  184.  
  185.     - huge model in Borland (data pointers far): there is no DGROUP, so
  186.       the 64K limit doesn't apply.
  187.  
  188.     In all of the above, which is to say all six models in Microsoft C
  189.     and all but huge in Borland C, DGROUP is limited to 64K including
  190.     string literals (which are treated as static data).  This limitation
  191.     is due to the Intel CPU's segmented architecture.
  192.  
  193.     See the next Q for possible remedies.
  194.  
  195.     For more information, see topics like "memory models" and "memory
  196.     management" in the index of your compiler manual.  Also see
  197.     TI738.ASC in PD1:<MSDOS.TURBO-C>BCHELP10.ZIP at Simtel for an
  198.     extended general discussion of memory usage in Borland C programs,
  199.     of which much applies to any C compiler in DOS.
  200.  
  201. Q202. How do I fix "automatic data segment exceeds 64K" or "stack plus
  202.       data exceed 64K"?
  203.  
  204.     These messages are a variation of "DGROUP > 64K".  For causes,
  205.     please see the preceding Q.
  206.  
  207.     If you get this error in tiny model, your program is simply too big
  208.     and you must use a different memory model.  If you get this link
  209.     error in models S, C, M, L, or Microsoft's H, there are some things
  210.     you can do.  (This error can't occur in Borland's huge model.)
  211.  
  212.     If you have one or two big global arrays, simply declare them far.
  213.     The compiler takes this to mean that any references to them will use
  214.     32-bit pointers, so they'll be in separate segments and no longer
  215.     part of DGROUP.
  216.  
  217.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  218.     with Borland C++ 2.0 and up.  This will automatically put variables
  219.     above a certain size into their own segments outside of DGROUP.
  220.  
  221.     Yet another option is to change global arrays to far pointers.  Then
  222.     at the beginning of your program, allocate them from the far heap
  223.     (_fmalloc in Microsoft, farmalloc in Borland).
  224.  
  225.     Finally, you can change to huge model (with Borland compilers, not
  226.     Microsoft).  Borland's H model still uses far pointers by default,
  227.     but "sets aside the [64K] limit" and has no DGROUP group, according
  228.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  229.     huge data pointers by default but retains DGROUP and its 64K limit,
  230.     so switching to the H model doesn't buy you anything if you have
  231.     DGROUP problems.
  232.  
  233. Q203. Will Borland C code and Microsoft C code link together?
  234.  
  235.     Typically this question is asked by someone who owns compiler A and
  236.     is trying to write code to link with a third-party library that was
  237.     compiled under compiler B.
  238.  
  239.     The answer to the question is, Not in general.  Here are some of the
  240.     reasons:
  241.  
  242.     - "Helper" functions (undocumented functions for stack checking,
  243.       floating-point arithmetic, and operations on longs) differ between
  244.       the two compilers.
  245.  
  246.     - The compilers may embed instructions in the object code that tell
  247.       the linker to look for their own run-time libraries.
  248.  
  249.     Those problems will generate link-time errors.  Others may not show
  250.     up until run time:
  251.  
  252.     - Borland's compact, large, and huge models don't assume DS=SS, but
  253.       Microsoft's do.  The -Fs option on the Borland compiler, or one of
  254.       the /A options on Microsoft, should take care of this problem --
  255.       once you know that's what's going on.
  256.  
  257.     - Check conventions for ordering and packing structure members, and
  258.       for alignment of various types on byte, word, paragraph, or other
  259.       boundaries.  Again, you can generally adjust your code to match if
  260.       you know what conventions were used in compiling the "foreign"
  261.       libraries.
  262.  
  263.     - Check the obvious and make sure that your code was compiled under
  264.       the same memory model as the code you're trying to link with.
  265.       (That's necessary, but no guarantee.  Microsoft and Borland don't
  266.       use exactly the same conventions for segments and groups,
  267.       particularly in the larger memory models.)
  268.  
  269.     That said, there are some circumstances where you can link hybrids.
  270.     Your best chance of success comes if you avoid longs and floating
  271.     point, use only 16-bit pointers, suppress stack checking, and
  272.     specify all libraries used in the link.
  273.  
  274. Q204. Why did my program bomb at run time with "floating point formats
  275.       not linked"?
  276.  
  277.     First, is that the actual message, or did it say "floating point not
  278.     loaded"?  If it was the latter, see the next Q.
  279.  
  280.     You're probably using a Borland compiler for C or C++ (including
  281.     Turbo C and Turbo C++).  Borland's compilers try to be smart and not
  282.     link in the floating-point (f-p) library unless you need it.  Alas,
  283.     they all get the decision wrong.  One common case is where you don't
  284.     call any f-p functions, but you have %f or other f-p formats in
  285.     scanf/printf calls.  The cure is to call an f-p function, or at
  286.     least force one to be present in the link.
  287.  
  288.     To do that, define this function somewhere in a source file but
  289.     don't call it:
  290.  
  291.         static void forcefloat(float *p)
  292.             { float f = *p; forcefloat(&f); }
  293.  
  294.     It doesn't have to be in the module with the main program, as long
  295.     as it's in a module that will be included in the link.
  296.  
  297.     A new solution for Borland C++ 3.0 was posted, but I don't own the
  298.     product and have not been able to verify it.  Insert these
  299.     statements in your program:
  300.  
  301.         extern unsigned _floatconvert;
  302.         #pragma extref _floatconvert
  303.  
  304. Q205. Why did my program bomb with "floating point not loaded"?
  305.  
  306.     That is Microsoft C's run-time message when the code requires a
  307.     numeric coprocessor but your computer doesn't have one installed.
  308.  
  309.     If the program is yours, relink it using the xLIBCE or xLIBCA
  310.     library (where x is the memory model).
  311.  
  312. Q206. How can I change the stack size in Borland's C compilers?
  313.  
  314.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  315.     size" in the index but the global variable _stklen should be there.
  316.     The manual will instruct you to put a statement like
  317.  
  318.         extern unsigned _stklen = 54321U;
  319.  
  320.     in your code, outside of any function.  You must assign the value
  321.     right in the extern statement; it won't work to assign a value at
  322.     run time.  (The "extern" in this context isn't ANSI C and ought not
  323.     to be required, but the above statement is a direct quote from the
  324.     Library Reference manual of Borland C++ 2.0.)  The linker may give
  325.     you a duplicate symbol warning, which you can ignore.
  326.  
  327. Q207. What's the difference between .COM and .EXE formats?
  328.  
  329.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  330.     file will undergo some further relocation when it is run (and so it
  331.     begins with a relocation header).  A .COM file is limited to 64K for
  332.     all segments combined, but an .EXE file can have as many segments as
  333.     your linker will handle and be as large as RAM can take.
  334.  
  335.     Among the books that detail formats of executable files are {DOS
  336.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  337.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  338.     ISBN 1-55615-329-5.  Ralf Brown's interrupt list also documents the
  339.     .EXE header (including extensions by Borland's TLINK) at INT 21
  340.     function 4B, including New Executable and Linear Executable formats.
  341.  
  342.  
  343. section 3. Keyboard
  344. ===================
  345.  
  346. Q301. How can I read a character without echoing it to the screen, and
  347.       without waiting for the user to press the Enter key?
  348.  
  349.     The C compilers from Microsoft and Borland offer getch (or getche to
  350.     echo the character); Turbo Pascal has ReadKey.
  351.  
  352.     In other programming languages, load 8 in register AH and execute
  353.     INT 21; AL is returned with the character from standard input
  354.     (possibly redirected).  If you don't want to allow redirection, or
  355.     you want to capture Ctrl-C and other special keys, use INT 16 with
  356.     AH=10; this will return the scan code in AH and ASCII code (if
  357.     possible) in AL, except that AL=E0 with AH nonzero indicates one of
  358.     the grey "extended" keys was pressed.  (If your BIOS doesn't
  359.     support the extended keyboard, use INT 16 function 0 not 10.)
  360.  
  361. Q302. How can I find out whether a character has been typed, without
  362.       waiting for one?
  363.  
  364.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  365.     the kbhit( ) function.  All of these tell you whether a key has been
  366.     pressed.  If no key has been pressed, they return that information
  367.     to your program.  If a keystroke is waiting, they tell your program
  368.     that but leave the key in the input buffer.
  369.  
  370.     You can use the BIOS call, INT 16 function 01 or 11, to check
  371.     whether an actual keystroke is waiting; or the DOS call, INT 21
  372.     function 0B, to check for a keystroke from stdin (subject to
  373.     redirection).  See Ralf Brown's interrupt list.
  374.  
  375. Q303. How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  376.  
  377.     You can download the file PD1:<MSDOS.KEYBOARD>CADEL.ZIP from Simtel.
  378.     It contains a TSR to disable those keys, with source code in ASM.
  379.  
  380.     To disable only Ctrl-Alt-Del (actually, to change the boot keys to
  381.     leftShift-Alt-Del), use DEBOOT.COM.  Along with KEYKILL.COM, which
  382.     lets you disable up to three keys of your choice, it is at Simtel in
  383.     the file PD1:<MSDOS.KEYBOARD>KEYKILL.ARC.
  384.  
  385.     C programmers who simply want to make sure that the user can't
  386.     Ctrl-Break out of their program can use the ANSI-standard signal( )
  387.     function; the Borland compilers also offer ctrlbrk( ) for handling
  388.     Ctrl-Break.  However, if your program uses normal DOS input, the
  389.     characters ^C will appear on the screen when the user presses Ctrl-C
  390.     or Ctrl-Break.  There are many ways to work around that, including:
  391.     use INT 21 function 7, which allows redirection but doesn't display
  392.     the ^C (or echo any other character, for that matter); or use INT 16
  393.     function 0 or 10; or call _bios_keybrd( ) in MSC or bioskey( ) in
  394.     BC++; or hook INT 9 to discard Ctrl-C and Ctrl-Break before the
  395.     regular BIOS keyboard handler sees them; etc., etc.
  396.  
  397.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  398.     differently internally.  Ctrl-Break, like all keystrokes, is
  399.     processed by the BIOS code at INT 9 as soon as the user presses the
  400.     keys, even if earlier keys are still in the keyboard buffer:  by
  401.     default the handler at INT 1B is called.  Ctrl-C is not special to
  402.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  403.     special to DOS functions 1 and 8 when at the head of the keyboard
  404.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  405.     polling the keyboard for Ctrl-C during non-keyboard operations.
  406.  
  407.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  408.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  409.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  410.     the IBM PC}, ISBN 0-942386-92-2.
  411.  
  412. Q304. How can I disable the print screen function?
  413.  
  414.     There are really two print screen functions:  1) print current
  415.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or
  416.     Shift-grey*, and 2) turn on continuous screen echo, started and
  417.     stopped by Ctrl-P or Ctrl-PrtSc.
  418.  
  419.     1) Screen snapshot to printer
  420.        --------------------------
  421.  
  422.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  423.     with that interrupt handler.  The standard handler, in BIOSes dated
  424.     December 1982 or later, uses a byte at 0040:0100 (alias 0000:0500)
  425.     to determine whether a print screen is currently in progress.  If it
  426.     is, pressing PrintScreen again is ignored.  So to disable the screen
  427.     snapshot, all you have to do is write a 1 to that byte.  When the
  428.     user presses PrintScreen, the BIOS will think that a print screen is
  429.     already in progress and will ignore the user's keypress.  You can
  430.     re-enable PrintScreen by zeroing the same byte.
  431.  
  432.     Here's some simple code:
  433.  
  434.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  435.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  436.             *flag = (unsigned char)!allow;
  437.         }
  438.  
  439.     2) Continuous echo of screen to printer
  440.        ------------------------------------
  441.  
  442.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  443.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  444.     "printing" strings like these to the screen (BASIC print, C printf,
  445.     Pascal Write statements, or ECHO command in batch files):
  446.  
  447.         <27>[0;114;"Ctrl-PrtSc disabled"p
  448.         <27>[16;"^P"p
  449.  
  450.     Change <27> in the above to an Escape character, ASCII 27.
  451.  
  452.     If you haven't installed ANSI.SYS, I can't offer an easy way to
  453.     disable the echo-screen-to-printer function.  Please send any tested
  454.     solutions to brown@ncoast.org and I'll add them to this list.
  455.  
  456.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  457.     your only concern is not locking up your machine, when you see the
  458.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  459.     I.  As an alternative, install one of the many print spoolers that
  460.     intercept printer-status queries and always return "Printer ready".
  461.  
  462. Q305. How can my program turn NumLock (CapsLock, ScrollLock) on or off?
  463.  
  464.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  465.     some code:  lck( ) turns on a lock state, and unlck( ) turns it off.
  466.     (The status lights on some keyboards may not reflect the change.  If
  467.     yours is one, call INT 16 function 2, "get shift status", and that
  468.     may update them.  It will certainly do no harm.)
  469.  
  470.         #define NUM_LOCK  (1 << 5)
  471.         #define CAPS_LOCK (1 << 6)
  472.         #define SCRL_LOCK (1 << 4)
  473.         void lck(int shiftype) {
  474.             char far* kbdstatus = (char far*)0x00400017UL;
  475.             *kbdstatus |= (char)shiftype;
  476.         }
  477.         void unlck(int shiftype) {
  478.             char far* kbdstatus = (char far*)0x00400017UL;
  479.             *kbdstatus &= ~(char)shiftype;
  480.         }
  481.  
  482. Q306. How can I speed up the keyboard's auto-repeat?
  483.  
  484.     The keyboard speed has two components: delay (before a key that you
  485.     hold down starts repeating) and typematic rate (the speed once the
  486.     key starts repeating).  Most BIOSes since 1986 let software change
  487.     the delay and typematic rate by calling INT 16 function 3, "set
  488.     typematic rate and delay"; see Ralf Brown's interrupt list.  If you
  489.     have DOS 4.0 or later, you can use the MODE CON command that you'll
  490.     find in your DOS manual.
  491.  
  492.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  493.     easily be changed.  According to the {PC Magazine} of 15 Jan 1991,
  494.     page 409, to adjust the typematic rate you need "a memory-resident
  495.     program which simply '[watches]' the keyboard to see if you're
  496.     holding down a key ... and after a certain time [starts] stuffing
  497.     extra copies of the held-down key into the buffer."  No source code
  498.     is given in that issue; but I'm told that the QUICKEYS utility that
  499.     {PC} published in 1986 does this sort of watching; you can download
  500.     source and object code in PD1:<MSDOS.PCMAG>VOL5N05.ARC from Simtel.
  501.  
  502. Q307. What is the SysRq key for?
  503.  
  504.     There is no standard use for the key.  The BIOS keyboard routines in
  505.     INT 16 simply ignore it; therefore so do the DOS input routines in
  506.     INT 21 as well as the keyboard routines in libraries supplied with
  507.     high-level languages.
  508.  
  509.     When you press or release a key, the keyboard triggers hardware line
  510.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  511.     keyboard and the shift states from the BIOS data area.
  512.  
  513.     What happens next depends on whether your PC's BIOS supports an
  514.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  515.     function 4F to translate the scan code.  If the translated scan code
  516.     is 54 hex (for the SysRq key) then INT 9 calls INT 15 function 85
  517.     and doesn't put the keystroke into the keyboard buffer.  The default
  518.     handler of that function does nothing and simply returns.  (If your
  519.     PC has an older BIOS that doesn't support the extended keyboards,
  520.     INT 15 function 4F is not called.  Early ATs have 84-key keyboards,
  521.     so their BIOS calls INT 15 function 85 but nor 4F.)
  522.  
  523.     Thus your program is free to use SysRq for its own purposes, but at
  524.     the cost of some programming.  You could hook INT 9, but it's
  525.     probably easier to hook INT 15 function 85, which is called when
  526.     SysRq is pressed or released.
  527.  
  528. Q308. How can my program tell what kind of keyboard is on the system?
  529.  
  530.     Ralf Brown's Interrupt List includes MEMORY.LST, a detailed
  531.     breakdown by Robin Walker of the contents of the BIOS system block
  532.     that starts at 0040:0000.  Bit 4 of byte 0040:0096 is "1=enhanced
  533.     keyboard installed".  C code to test the keyboard type:
  534.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  535.         if (0x10 & *kbd_stat_byte3)
  536.             /* 101- or 102-key keyboard is installed */
  537.  
  538.     {PC Magazine}'s 15 Jan 1991 issue suggests on page 412 that "for
  539.     some clones [the above test] is not foolproof".  If you use this
  540.     method in your program you should provide the user some way to
  541.     override this test, or at least some way to tell your program to
  542.     assume a non-enhanced keyboard.  The {PC Magazine} article suggests
  543.     a different approach to determining the type of keyboard.
  544.  
  545. Q309. How can I tell if input, output, or stderr has been redirected?
  546.  
  547.     Normally, input and output are associated with the console (i.e.,
  548.     with the keyboard and the screen, respectively).  If either is not,
  549.     you know that it has been redirected.  Some source code to check
  550.     this is available at the usual archive sites.
  551.  
  552.     If you program in Turbo Pascal, download the /pc/ts/tspa*.zip
  553.     collection of Turbo Pascal units from garbo; or from Simtel,
  554.     PD1:<MSDOS.TURBOPAS>TSPA*.ZIP.  (Choose TSPA3060.ZIP, TSPA3055.ZIP,
  555.     TSPA3050.ZIP, or TSPA3040.ZIP for Turbo Pascal 6.0, 5.5, 5.0, or 4.0
  556.     respectively.)  Source code is not included.  Also see the
  557.     information in garbo.uwasa.fi:/pc/ts/tsfaq*.zip Frequently Asked
  558.     Questions, the Turbo Pascal section.
  559.  
  560.     If you program in C, use isatty( ) if your implementation has it.
  561.     Otherwise, you can download PD1:<MSDOS.SYSUTL>IS_CON10.ZIP from
  562.     Simtel; it includes source code.
  563.  
  564.     Good references for the principles are {PC Magazine} 16 Apr 1991
  565.     (vol 10 nr 7) pg 374; Ray Duncan's {Advanced MS-DOS}, ISBN
  566.     1-55615-157-8, or Ralf Brown's interrupt list for INT 21 function
  567.     4400; and Terry Dettman and Jim Kyle's {DOS Programmer's Reference:
  568.     2d edition}, ISBN 0-88022-458-4, pp 602-603.
  569.  
  570. (continued in part 3)
  571. -- 
  572. Stan Brown, Oak Road Systems                      brown@Ncoast.ORG
  573. Cleveland, Ohio, USA
  574.