home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8077 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  25.3 KB

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