home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9141 < prev    next >
Encoding:
Text File  |  1992-09-08  |  25.7 KB  |  553 lines

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