home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 8809 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  25.8 KB

  1. Xref: sparky comp.os.msdos.programmer:8809 news.answers:2625
  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: Sat, 10 Oct 1992 00:25:16 GMT
  7. Organization: Oak Road Systems, Cleveland Ohio USA
  8. Date: Wed, 26 Aug 1992 00:25:16 GMT
  9. Approved: news-answers-request@MIT.Edu
  10. Message-ID: <msdos-faq.920825.2@NCoast.ORG>
  11. Followup-To: comp.os.msdos.programmer
  12. References: <msdos-faq.920825.1@NCoast.ORG>
  13. Supersedes: <1992Jul25.161105.6972@NCoast.ORG>
  14. Lines: 539
  15.  
  16. Archive-name: msdos-programmer-faq/part2
  17. Last-modified: 22 August 1992
  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. in the last part of this list 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 Feb 92" in news.lists shows 62,000 readers of
  71.     this newsgroup.
  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 is where you post notices of equipment,
  122.       software, or computer books that you want to sell.  Please don't
  123.       post or crosspost those notices here.
  124.  
  125.     - comp.os.ms-windows.programmer.tools and ...misc (formerly part of
  126.       comp.windows.ms.programmer):  Similar to this group, but focus
  127.       on programming for the MS-Windows platform.
  128.  
  129.     - comp.sys.ibm.pc.hardware is for more hardware-oriented discussions
  130.       of the machines that run DOS.
  131.  
  132.     - comp.binaries.ibm.pc.wanted: AFTER you have looked in the other
  133.       groups, this is the place to post a request for a particular
  134.       binary program.
  135.  
  136.     - comp.binaries.ibm.pc.archives explains how to use the archive
  137.       sites, especially garbo and Simtel.  Look for the excellent
  138.       periodic postings, such as "Recent msdos uploads to SIMTEL20".
  139.  
  140.     - comp.binaries.ibm.pc.d is for discussions about programs posted in
  141.       comp.binaries.ibm.pc, and only those programs.  This is a good
  142.       place to report bugs in the programs, but not to ask where to find
  143.       them (see cbip.wanted, above).  cbip.d is NOT supposed to be a
  144.       general PC discussion group.
  145.  
  146.     - comp.sources.misc: a moderated group for source code for many
  147.       computer systems.  It tends to get lots of Unix stuff, but you may
  148.       also pick up some DOS-compatible code here.
  149.  
  150.     - alt.sources: an unmoderated group for source code.  Guidelines are
  151.       posted periodically.
  152.  
  153.  
  154. section 2. Compile and link
  155. ===========================
  156.  
  157. Q201. What the heck is "DGROUP > 64K"?
  158.  
  159.     DGROUP is a link-time group of data segments, and the compiler
  160.     typically generates code that expects DS to be pointing to DGROUP.
  161.     (Exception: Borland's huge model has no DGROUP.)
  162.  
  163.     Here's what goes into DGROUP:
  164.  
  165.     - tiny model (all pointers near):  DGROUP holds the entire program.
  166.  
  167.     - small and medium models (data pointers near):  DGROUP holds all
  168.       globals and static variables including string literals, plus the
  169.       stack and the heap.
  170.  
  171.     - large, compact, and huge models in Microsoft (data pointers far):
  172.       DGROUP holds only initialized globals and static variables
  173.       including string literals, plus the stack and the near heap.
  174.  
  175.     - large and compact models in Borland (data pointers far): DGROUP
  176.       holds initialized and uninitialized globals and static variables
  177.       including string literals, but not the stack or heap.
  178.  
  179.     - huge model in Borland (data pointers far): there is no DGROUP, so
  180.       the 64K limit doesn't apply.
  181.  
  182.     In all of the above, which is to say all six models in Microsoft C
  183.     and all but huge in Borland C, DGROUP is limited to 64K including
  184.     string literals (which are treated as static data).  This limitation
  185.     is due to the Intel CPU's segmented architecture.
  186.  
  187.     See the next Q for possible remedies.
  188.  
  189.     For more information, see topics like "memory models" and "memory
  190.     management" in the index of your compiler manual.
  191.  
  192. Q202. How do I fix "automatic data segment exceeds 64K" or "stack plus
  193.       data exceed 64K"?
  194.  
  195.     These messages are a variation of "DGROUP > 64K".  For causes,
  196.     please see the preceding Q.
  197.  
  198.     If you get this error in tiny model, your program is simply too big
  199.     and you must use a different memory model.  If you get this link
  200.     error in models S, C, M, L, or Microsoft's H, there are some things
  201.     you can do.  (This error can't occur in Borland's huge model.)
  202.  
  203.     If you have one or two big global arrays, simply declare them far.
  204.     The compiler takes this to mean that any references to them will use
  205.     32-bit pointers, so they'll be in separate segments and no longer
  206.     part of DGROUP.
  207.  
  208.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  209.     with Borland C++ 2.0 and 3.0.  This will automatically put variables
  210.     above a certain size into their own segments outside of DGROUP.
  211.  
  212.     Yet another option is to change global arrays to far pointers.  Then
  213.     at the beginning of your program, allocate them from the far heap
  214.     (_fmalloc in Microsoft, farmalloc in Borland).
  215.  
  216.     Finally, you can change to huge model (with Borland compilers, not
  217.     Microsoft).  Borland's H model still uses far pointers by default,
  218.     but "sets aside [the 64K] limit" and has no DGROUP group, according
  219.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  220.     huge data pointers by default but retains DGROUP and its 64K limit,
  221.     so switching to the H model doesn't buy you anything if you have
  222.     DGROUP problems.
  223.  
  224. Q203. Will Borland C code and Microsoft C code link together?
  225.  
  226.     Not in general.  The usual context for this question is that you've
  227.     bought a package of application .OBJs or .LIBs that were meant for
  228.     use with a compiler that you don't have.
  229.  
  230.     One problem is that each compiler uses calls to undocumented
  231.     functions to do things like long integer arithmetic, floating point
  232.     arithmetic, and stack checking.  And the undocumented functions from
  233.     Microsoft are not the same as those from Borland.  So a link will
  234.     generally fail with "not found" messages for oddball function names
  235.     that you can't find in the manuals.  Although the link fails, it
  236.     usually creates an .EXE file.  But if you try to run the program, it
  237.     crashes as soon as it tries to call one of those functions.
  238.  
  239.     Another problem is that Borland's compact, large, and huge models
  240.     don't assume DS=SS, but Microsoft's do.  The -Fs option on the
  241.     Borland compiler, or one of the /A options on Microsoft, should take
  242.     care of this problem.
  243.  
  244.     A third-party vendor of compiled object libraries can take some
  245.     steps to minimize such problems, but it's usually far more cost
  246.     effective for the vendor to issue different versions of the software
  247.     to be used with different compilers.  I looked at this problem a
  248.     year or so ago for a client.  The choice was between severely
  249.     restricting functions of the libraries the client would distribute,
  250.     or distributing them in companion disks for use with Microsoft and
  251.     Borland respectively.  The client chose the latter solution, which
  252.     still seems to me the right one.
  253.  
  254. Q204. Why did my program bomb at run time with "floating point formats
  255.       not linked"?
  256.  
  257.     First, is that the actual message, or did it say "floating point not
  258.     loaded"?  If it was the latter, see the next Q.
  259.  
  260.     You're probably using a Borland compiler for C or C++ (including
  261.     Turbo C and Turbo C++).  Borland's compilers try to be smart and not
  262.     link in the floating-point (f-p) library unless you need it.  Alas,
  263.     they all get the decision wrong.  One common case is where you don't
  264.     call any f-p functions, but you have %f or other f-p formats in
  265.     scanf/printf calls.  The cure is to call an f-p function, or at
  266.     least force one to be present in the link.
  267.  
  268.     To do that, define this function somewhere in a source file but
  269.     don't call it:
  270.  
  271.         static void forcefloat(float *p)
  272.             { float f = *p; forcefloat(&f); }
  273.  
  274.     It doesn't have to be in the module with the main program, as long
  275.     as it's in a module that will be included in the link.
  276.  
  277.     A new solution for Borland C++ 3.0 was posted, but I don't own the
  278.     product and have not been able to verify it.  Insert these
  279.     statements in your program:
  280.  
  281.         extern unsigned _floatconvert;
  282.         #pragma extref _floatconvert
  283.  
  284. Q205. Why did my program bomb with "floating point not loaded"?
  285.  
  286.     That is Microsoft C's run-time message when the code requires a
  287.     numeric coprocessor but your computer doesn't have one installed.
  288.  
  289.     If the program is yours, relink it using the xLIBCE or xLIBCA
  290.     library (where x is the memory model).
  291.  
  292. Q206. How can I change the stack size in Borland's C compilers?
  293.  
  294.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  295.     size" in the index but the global variable _stklen should be there.
  296.     The manual will instruct you to put a statement like
  297.  
  298.         extern unsigned _stklen = 54321U;
  299.  
  300.     in your code, outside of any function.  You must assign the value
  301.     right in the extern statement; it won't work to assign a value at
  302.     run time.  (The "extern" in this context isn't ANSI C and ought not
  303.     to be required, but the above statement is a direct quote from the
  304.     Library Reference manual of Borland C++ 2.0.)  The linker may give
  305.     you a duplicate symbol warning, which you can ignore.
  306.  
  307. Q207. What's the difference between .COM and .EXE formats?
  308.  
  309.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  310.     file will undergo some further relocation when it is run (and so it
  311.     begins with a relocation header).  A .COM file is limited to 64K for
  312.     all segments combined, but an .EXE file can have as many segments as
  313.     your linker will handle and be as large as RAM can take.
  314.  
  315.     Among the books that detail formats of executable files are {DOS
  316.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  317.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  318.     ISBN 1-55615-329-5.  Ralf Brown's interrupt list also documents the
  319.     .EXE header (including extensions by Borland's TLINK) at INT 21
  320.     function 4B, including New Executable and Linear Executable formats.
  321.  
  322.  
  323. section 3. Keyboard
  324. ===================
  325.  
  326. Q301. How can I read a character without echoing it to the screen, and
  327.       without waiting for the user to press the Enter key?
  328.  
  329.     The C compilers from Microsoft and Borland offer getch (or getche to
  330.     echo the character); Turbo Pascal has ReadKey.
  331.  
  332.     In other programming languages, load 8 in register AH and execute
  333.     INT 21; AL is returned with the character from standard input
  334.     (possibly redirected).  If you don't want to allow redirection, or
  335.     you want to capture Ctrl-C and other special keys, use INT 16 with
  336.     AH=10; this will return the scan code in AH and ASCII code (if
  337.     possible) in AL, except that AL=E0 with AH nonzero indicates one of
  338.     the grey "extended" keys was pressed.  (If your BIOS doesn't
  339.     support the extended keyboard, use INT 16 function 0 not 10.)
  340.  
  341. Q302. How can I find out whether a character has been typed, without
  342.       waiting for one?
  343.  
  344.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  345.     the kbhit( ) function.  All of these tell you whether a key has been
  346.     pressed.  If no key has been pressed, they return that information
  347.     to your program.  If a keystroke is waiting, they tell your program
  348.     that but leave the key in the input buffer.
  349.  
  350.     You can use the BIOS call, INT 16 function 01 or 11, to check
  351.     whether an actual keystroke is waiting; or the DOS call, INT 21
  352.     function 0B, to check for a keystroke from stdin (subject to
  353.     redirection).  See Ralf Brown's interrupt list.
  354.  
  355. Q303. How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  356.  
  357.     You can download the file PD1:<MSDOS.KEYBOARD>CADEL.ZIP, 2534 bytes,
  358.     from Simtel.  It contains a TSR to do disable those three keys, with
  359.     source code in ASM.
  360.  
  361.     To disable only Ctrl-Alt-Del (actually, to change the boot keys to
  362.     leftShift-Alt-Del), use DEBOOT.COM.  Along with KEYKILL.COM, which
  363.     lets you disable up to three keys of your choice, it is at Simtel in
  364.     the file PD1:<MSDOS.KEYBOARD>KEYKILL.ARC, 3395 bytes.
  365.  
  366.     C programmers who simply want to make sure that the user can't
  367.     Ctrl-Break out of their program can use the ANSI-standard signal( )
  368.     function; the Borland compilers also offer ctrlbrk( ) for handling
  369.     Ctrl-Break.  However, if your program uses normal DOS input, the
  370.     characters ^C will appear on the screen when the user presses Ctrl-C
  371.     or Ctrl-Break.  There are many ways to work around that, including:
  372.     use INT 21 function 7, which allows redirection but doesn't display
  373.     the ^C (or echo any other character, for that matter); or use INT 16
  374.     function 0 or 10; or call _bios_keybrd( ) in MSC or bioskey( ) in
  375.     BC++; or hook INT 9 to discard Ctrl-C and Ctrl-Break before the
  376.     regular BIOS keyboard handler sees them; etc., etc.
  377.  
  378.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  379.     differently internally.  Ctrl-Break, like all keystrokes, is
  380.     processed by the BIOS code at INT 9 as soon as the user presses the
  381.     keys, even if earlier keys are still in the keyboard buffer:  by
  382.     default the handler at INT 1B is called.  Ctrl-C is not special to
  383.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  384.     special to DOS functions 1 and 8 when at the head of the keyboard
  385.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  386.     polling the keyboard for Ctrl-C during non-keyboard operations.
  387.  
  388.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  389.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  390.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  391.     the IBM PC}, ISBN 0-942386-92-2.
  392.  
  393. Q304. How can I disable the print screen function?
  394.  
  395.     There are really two print screen functions:  1) print current
  396.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or
  397.     Shift-grey*, and 2) turn on continuous screen echo, started and
  398.     stopped by Ctrl-P or Ctrl-PrtSc.
  399.  
  400.     1) Screen snapshot to printer
  401.        --------------------------
  402.  
  403.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  404.     with that interrupt handler.  The standard handler, in BIOSes dated
  405.     December 1982 or later, uses a byte at 0040:0100 (alias 0000:0500)
  406.     to determine whether a print screen is currently in progress.  If it
  407.     is, pressing PrintScreen again is ignored.  So to disable the screen
  408.     snapshot, all you have to do is write a 1 to that byte.  When the
  409.     user presses PrintScreen, the BIOS will think that a print screen is
  410.     already in progress and will ignore the user's keypress.  You can
  411.     re-enable PrintScreen by zeroing the same byte.
  412.  
  413.     Here's some simple code (tested under MSC 5.0 and BC++ 2.0):
  414.  
  415.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  416.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  417.             *flag = (unsigned char)!allow;
  418.         }
  419.  
  420.     2) Continuous echo of screen to printer
  421.        ------------------------------------
  422.  
  423.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  424.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  425.     "printing" strings like these to the screen (BASIC print, C printf,
  426.     Pascal Write statements, or ECHO command in batch files):
  427.  
  428.         <27>[0;114;"Ctrl-PrtSc disabled"p
  429.         <27>[16;"^P"p
  430.  
  431.     Change <27> in the above to an Escape character, ASCII 27.
  432.  
  433.     If you haven't installed ANSI.SYS, I can't offer an easy way to
  434.     disable the echo-screen-to-printer function.  Please send any tested
  435.     solutions to brown@ncoast.org and I'll add them to this list.
  436.  
  437.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  438.     your only concern is not locking up your machine, when you see the
  439.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  440.     I.  As an alternative, install one of the many print spoolers that
  441.     intercept printer-status queries and always return "Printer ready".
  442.  
  443. Q305. How can my program turn NumLock (CapsLock, ScrollLock) on or off?
  444.  
  445.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  446.     some code (tested under MSC 5.0 and BC++ 2.0):  lck( ) turns on a
  447.     lock state, and unlck( ) turns it off.  (The status lights on some
  448.     keyboards may not reflect the change.  If yours is one, call INT 16
  449.     function 2, "get shift status", and that may update them.  It will
  450.     certainly do no harm.)
  451.  
  452.         #define NUM_LOCK  (1 << 5)
  453.         #define CAPS_LOCK (1 << 6)
  454.         #define SCRL_LOCK (1 << 4)
  455.         void lck(int shiftype) {
  456.             char far* kbdstatus = (char far*)0x00400017UL;
  457.             *kbdstatus |= (char)shiftype;
  458.         }
  459.         void unlck(int shiftype) {
  460.             char far* kbdstatus = (char far*)0x00400017UL;
  461.             *kbdstatus &= ~(char)shiftype;
  462.         }
  463.  
  464. Q306. How can I speed up the keyboard's auto-repeat?
  465.  
  466.     The keyboard speed has two components: delay (before a key that you
  467.     hold down starts repeating) and typematic rate (the speed once the
  468.     key starts repeating).  Most BIOSes since 1986 let software change
  469.     the delay and typematic rate by calling INT 16 function 3, "set
  470.     typematic rate and delay"; see Ralf Brown's interrupt list.  If you
  471.     have DOS 4.0 or later, you can use the MODE CON command that you'll
  472.     find in your DOS manual.
  473.  
  474.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  475.     easily be changed.  According to the {PC Magazine} of 15 Jan 1991,
  476.     page 409, to adjust the typematic rate you need "a memory-resident
  477.     program which simply '[watches]' the keyboard to see if you're
  478.     holding down a key ... and after a certain time [starts] stuffing
  479.     extra copies of the held-down key into the buffer."  No source code
  480.     is given in that issue; but I'm told that the QUICKEYS utility that
  481.     {PC} published in 1986 does this sort of watching; you can download
  482.     source and object code in PD1:<MSDOS.PCMAG>VOL5N05.ARC from Simtel.
  483.  
  484. Q307. What is the SysRq key for?
  485.  
  486.     There is no standard use for the key.  The BIOS keyboard routines in
  487.     INT 16 simply ignore it; therefore so do the DOS input routines in
  488.     INT 21 as well as the keyboard routines in libraries supplied with
  489.     high-level languages.
  490.  
  491.     When you press or release a key, the keyboard triggers hardware line
  492.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  493.     keyboard and the shift states from the BIOS data area.
  494.  
  495.     What happens next depends on whether your PC's BIOS supports an
  496.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  497.     function 4F to translate the scan code.  If the translated scan code
  498.     is 54 hex (for the SysRq key) then INT 9 calls INT 15 function 85
  499.     and doesn't put the keystroke into the keyboard buffer.  The default
  500.     handler of that function does nothing and simply returns.  (If your
  501.     PC has an older BIOS that doesn't support the extended keyboards,
  502.     INT 15 function 4F is not called.  Early ATs have 84-key keyboards,
  503.     so their BIOS calls INT 15 function 85 but nor 4F.)
  504.  
  505.     Thus your program is free to use SysRq for its own purposes, but at
  506.     the cost of some programming.  You could hook INT 9, but it's
  507.     probably easier to hook INT 15 function 85, which is called when
  508.     SysRq is pressed or released.
  509.  
  510. Q308. How can my program tell what kind of keyboard is on the system?
  511.  
  512.     Ralf Brown's Interrupt List has a detailed breakdown of the contents
  513.     of the BIOS system block that starts at 0040:0000.  Bit 4 of byte
  514.     0040:0096 is "1=enhanced keyboard installed".
  515.  
  516.     This code is tested under MSC 5.0 and BC++ 2.0:
  517.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  518.         if (0x10 & *kbd_stat_byte3)
  519.             /* 101- or 102-key keyboard is installed */
  520.  
  521.     {PC Magazine}'s 15 Jan 1991 issue suggests on page 412 that "for
  522.     some clones [the above test] is not foolproof".  If you use this
  523.     method in your program you should provide the user some way to
  524.     override this test, or at least some way to tell your program to
  525.     assume a non-enhanced keyboard.  The {PC Magazine} article suggests
  526.     a different approach to determining the type of keyboard.
  527.  
  528. Q309. How can I tell if input or output has been redirected?
  529.  
  530.     Normally, input and output are associated with the console (i.e.,
  531.     with the keyboard and the screen, respectively).  If either is not,
  532.     you know that it has been redirected.  Some source code to check
  533.     this is available at the usual archive sites.
  534.  
  535.     If you program in Turbo Pascal, download the /pc/ts/tspa*.zip
  536.     collection of Turbo Pascal units from garbo; or from Simtel,
  537.     PD1:<MSDOS.TURBOPAS>TSPA*.ZIP.  Source code is not included.  Also
  538.     see the information in garbo.uwasa.fi:/pc/ts/tsfaq*.zip Frequently
  539.     Asked Questions, the Turbo Pascal section.
  540.  
  541.     If you program in C, use isatty( ) if your implementation has it.
  542.     Otherwise, you can download PD1:<MSDOS.SYSUTL>IS_CON10.ZIP, 4267
  543.     bytes (contains source code) from Simtel.
  544.  
  545.     Good references for the principles are {PC Magazine} 16 Apr 1991
  546.     (vol 10 nr 7) pg 374; Ray Duncan's {Advanced MS-DOS}, ISBN
  547.     1-55615-157-8, or Ralf Brown's interrupt list for INT 21 function
  548.     4400; and Terry Dettman and Jim Kyle's {DOS Programmer's Reference:
  549.     2d edition}, ISBN 0-88022-458-4, pp 602-603.
  550.  
  551. (continued in part 3)
  552. -- 
  553.  
  554. Stan Brown, Oak Road Systems                      brown@Ncoast.ORG
  555.