home *** CD-ROM | disk | FTP | other *** search
/ Danny Amor's Online Library / Danny Amor's Online Library - Volume 1.iso / html / faqs / faq / msdos / programmer-faq.part2 < prev    next >
Encoding:
Text File  |  1995-07-25  |  37.1 KB  |  792 lines

  1. Subject: comp.os.msdos.programmer FAQ part 2 of 4
  2. Newsgroups: comp.os.msdos.programmer,comp.answers,news.answers
  3. From: brown@NCoast.ORG (Stan Brown)
  4. Date: Sat, 25 Sep 1993 14:09:57 GMT
  5.  
  6. Archive-name: msdos-programmer-faq/part2
  7. Last-modified: 24 Sep 1993
  8.  
  9. (continued from part 1)         (no warranty on the code or information)
  10.  
  11. If the posting date is more than six weeks in the past, see instructions
  12. at the end of this article for how to get an updated copy.
  13.  
  14. Copyright (C) 1993  Stan Brown, Oak Road Systems.  All rights reserved.
  15.  
  16.  
  17. section 1. General questions
  18. ============================
  19.  
  20. Subject:  101. Why won't my code work?
  21.  
  22.     First you need to try to determine whether the problem is in your
  23.     use of the programming language or in your use of MSDOS and your PC
  24.     hardware.  (Your manual should tell you which features are standard
  25.     and which are vendor- or MSDOS- or PC-specific.  You _have_ read
  26.     your manual carefully, haven't you?)
  27.  
  28.     If the feature that seems to be working wrong is something related
  29.     to your PC hardware or to the internals of MS-DOS, this group is the
  30.     right place to ask.  (Please check this FAQ list first, to make sure
  31.     your question isn't already answered here.)
  32.  
  33.     On the other hand, if your problem is with the programming language,
  34.     the comp.lang hierarchy (including comp.lang.pascal and comp.lang c)
  35.     is probably a better resource.  Please read the other group's FAQ
  36.     list thoroughly before posting.  (These exist in comp.lang.c,
  37.     comp.lang.c++, comp.lang.modula3, comp.lang.lisp, comp.lang.perl;
  38.     they may exist in other groups as well.)  It's almost never a good
  39.     idea to crosspost between this group and a language group.
  40.  
  41.     Before posting in either place, try to make your program as small as
  42.     possible while still exhibiting the bad behavior.  Sometimes this
  43.     alone is enough to show you where the trouble is.  Also edit your
  44.     description of the problem to be as short as possible.  This makes
  45.     it look more like you tried to solve the problem on your own, and
  46.     makes people more inclined to try to help you.  See later in this
  47.     section for some important netiquette tips.
  48.  
  49. Subject:  102. What is this newsgroup about?
  50.  
  51.     (rev: 11 Sep 1993) comp.os.msdos.programmer (comp.sys.ibm.pc.programmer
  52.     until September 1990) concerns programming for MS-DOS systems.  The
  53.     article "USENET Readership report for Aug 93" in news.lists shows
  54.     78,000 readers of this newsgroup worldwide.  Traffic (exclusive of
  55.     crossposts) was 813 articles aggregating 1604 Kbytes.
  56.  
  57.     Much of our traffic is about language products (chiefly from Borland
  58.     and Microsoft).  More programming topics focus on C than on any one
  59.     other language, but we are not just for C programmers (see next Q).
  60.  
  61.     Since most MS-DOS systems run on hardware that is roughly compatible
  62.     with the IBM PC, on Intel 8088, 80188, or 80x86 chips, we tend to
  63.     get a lot of questions and answers about programming other parts of
  64.     the hardware.
  65.  
  66. Subject:  103. Is comp.os.msdos.programmer just for C programmers?
  67.  
  68.     (new: 12 Aug 1993)  No, it is for all programmers who to share
  69.     information about programming in MS-DOS.  Programs and questions are
  70.     also posted in Pascal, assembly, and other languages (including
  71.     MS-DOS batch programming.)
  72.  
  73.     Why does the newsgroup seem to be so C-oriented sometimes?  There
  74.     are two reasons.  First, comp.lang.c and comp.lang.pascal have
  75.     evolved in different directions.  comp.lang.pascal welcomes
  76.     vendor-specific discussion, such as Turbo Pascal.  Since so many of
  77.     TP's features are tailored to programming on PCs and in MS-DOS,
  78.     Turbo Pascal programmers tend to find DOS questions welcomed there,
  79.     so that comp.os.msdos.programmer gets less of the "DOS in Turbo
  80.     Pascal" traffic.  On the other hand, comp.lang.c has stayed closer
  81.     to talking only about the C language, and vendor-specific or
  82.     operating-system-specific questions are not welcome.  This tends to
  83.     push questions about disks, DOS file structure, video, the keyboard,
  84.     TSRs, etc. to c.o.m.p even when those programs are written in C.
  85.  
  86.     This FAQ is definitely C-oriented, not because that's necessarily
  87.     best but because the original editor tried to stick to what he could
  88.     verify personally.  As a C programmer (with some assembler), he
  89.     could most carefully verify solutions in C or assembler.  He felt
  90.     that short, clear programs could be published in just one language
  91.     and programmers could translate them into their languages of choice.
  92.     But the FAQ list also contains several long programs written only in
  93.     C; this is a defect with no obvious remedy.  Most answers that point
  94.     to source code at archive sites include both C- and Pascal-language
  95.     source when available; please draw any omissions to the editor's
  96.     attention.
  97.  
  98. Subject:  104. What's the difference from comp.sys.ibm.pc.programmer?
  99.  
  100.     c.s.i.p.programmer is the old name of comp.os.msdos.programmer, and
  101.     has been obsolete since September 1990.  However, many systems have
  102.     not removed the old group, or have removed it but aliased it to the
  103.     new name.  This means that some people still think they're posting
  104.     to c.s.i.p.programmer even though they're actually posting to
  105.     c.o.m.programmer.
  106.  
  107.     You can easily verify the non-existence of c.s.i.p.programmer by
  108.     reference to the "List of Active Newsgroups" posted to news.groups.
  109.     It's available as /pub/usenet/news.answers/active-newsgroups/part1
  110.     from the archives (see "Where are FAQ lists archived?" in section C,
  111.     "More information").
  112.  
  113. Subject:  105. Is comp.os.msdos.programmer available as a mailing list?
  114.  
  115.     (new: 2 Feb 1993)  Sorry, no.
  116.  
  117. Subject:  106. What's this "netiquette"?
  118.  
  119.     (new: 7 Aug 1993)  Netiquette is good Usenet etiquette.  It includes
  120.     basic rules like the following; see also the next Q.
  121.  
  122.     - Always read a newsgroup for a reasonable time before you post an
  123.       article to it.
  124.  
  125.     - Pick the one right group for your article; don't crosspost unless
  126.       absolutely necessary.  If you absolutely must post an article to
  127.       more than one group, do crosspost it and don't post the same
  128.       article separately to each group.
  129.  
  130.     - Before you post a question, make sure you're posting to the right
  131.       newsgroup--the best way to do that is to observe the preceding
  132.       rule.  Check the group's FAQ list (if it has one) to make sure
  133.       that your question isn't already answered there.  See "Where are
  134.       FAQ lists archived?" in section C, "More information".
  135.  
  136.     - When you post a question, if you ask for email responses then
  137.       promise to post a summary.  Keep your promise.  And make it a
  138.       real summary: don't just append all the email you got.  Instead,
  139.       write your own (brief) description of the solution:  this is the
  140.       best way to make sure you really understand it.
  141.  
  142.     - Before you post a follow-up, read the other follow-ups.  Very
  143.       often you'll find that someone else has already made the point you
  144.       had in mind.
  145.  
  146.     - When someone posts a question, if you want to know the answer
  147.       don't post a "me, too".  Instead send email to the poster asking
  148.       him or her to share responses with you.
  149.  
  150.     - When posting a follow-up to another posted article, remove all
  151.       headers and signature lines from the old article; just keep the
  152.       line "In <article>, so-and-so writes:".  Also cut the original
  153.       article down as much as possible; just keep enough of it to remind
  154.       readers of the context.
  155.  
  156.     - Keep lines in posted articles to 72-75 characters.  Many
  157.       newsreaders chop off column 81 or arbitrarily insert a newline
  158.       there, which makes longer lines difficult or impossible to read.
  159.       But you need to keep well below 80 characters per line to allow
  160.       for the > characters that get inserted when other people post
  161.       follow-ups to your article.
  162.  
  163.     - Keep your signature to 4 lines or less (including any graphics),
  164.       and for heaven's sake make sure it doesn't get posted twice in
  165.       your article.
  166.  
  167.     - Don't post email without first obtaining the permission of the
  168.       sender.
  169.  
  170. Subject:  107. How can I learn more about Usenet?
  171.  
  172.     (new: 7 Aug 1993)  There are two important newsgroups for learning
  173.     about how Usenet and newsreader software works:
  174.  
  175.     - news.announce.newusers contains periodic postings that everybody
  176.       is asked to read before posting anything to Usenet.  (In theory,
  177.       all new users are subscribed to news.announce.newusers
  178.       automatically.  But in practice not all newsreader software does
  179.       that, so that many people violate the guidelines given there
  180.       simply because they don't know about them.)
  181.  
  182.     - news.newusers.questions is described as "Q & A for users new to
  183.       the Usenet".  But new and long-time users can ask or answer
  184.       questions about Usenet and newsreader software there.  There's an
  185.       important article, "Welcome to news.newusers.questions! (weekly
  186.       posting)", that everyone is asked to read before posting to
  187.       news.newusers.questions.  (See below for ways to get a copy of
  188.       that article.)
  189.  
  190.     The following postings in news.announce.newusers might be considered
  191.     the "mandatory course" for new users:
  192.  
  193.         Introduction to news.announce.newusers
  194.         What is Usenet?
  195.         Answers to Frequently Asked Questions
  196.         Rules for posting to Usenet
  197.         A Primer on How to Work With the Usenet Community
  198.         Hints on writing style for Usenet
  199.         Emily Postnews Answers Your Questions on Netiquette
  200.  
  201.     The articles mentioned above are downloadable via ftp from
  202.     rtfm.mit.edu in the following files:
  203.  
  204.         /pub/usenet/news.answers/news-newusers-intro
  205.                 Welcome to news.newusers.questions! (weekly posting)
  206.         /pub/usenet/news.answers/news-announce-intro/part1
  207.                 Introduction to news.announce.newusers
  208.         /pub/usenet/news.answers/what-is-usenet/part1
  209.                 What is Usenet?
  210.         /pub/usenet/news.answers/usenet-faq/part1
  211.                 Answers to Frequently Asked Questions
  212.         /pub/usenet/news.answers/posting-rules/part1
  213.                 Rules for posting to Usenet
  214.         /pub/usenet/news.answers/usenet-primer/part1
  215.                 A Primer on How to Work With the Usenet Community
  216.         /pub/usenet/news.answers/usenet-writing-style/part1
  217.                 Hints on writing style for Usenet
  218.         /pub/usenet/news.answers/emily-postnews/part1
  219.                 Emily Postnews Answers Your Questions on Netiquette
  220.  
  221.     They are also available from the mail server whose address is
  222.     mail-server@rtfm.mit.edu.  Send a message containing one or more
  223.     "send" command lines such as
  224.  
  225.         send usenet/news.answers/news-newusers-intro
  226.  
  227.     The "send" filenames are the same as the ftp filenames except the
  228.     "/pub" at the beginning is omitted.  To get general information
  229.     about the mail server, send it a message containing "help".
  230.  
  231. Subject:  108. What other technical newsgroups should I know about?
  232.  
  233.     (rev: 16 Aug 1993)  Caution:  Some of these newsgroups have
  234.     specialized charters; you'll probably get (and deserve) some flames
  235.     if you post to an inappropriate group.  Most groups have FAQ lists
  236.     that will tell you what's appropriate.  Don't post a request for the
  237.     FAQ list; instead, retrieve it yourself--see "Where are FAQ lists
  238.     archived?", in section C, "More information".
  239.  
  240.     - misc.forsale.computers.d and misc.forsale.computers.pc-clone are
  241.       where you post notices of equipment, software, or computer books
  242.       that you want to sell.  Please don't post or crosspost those
  243.       notices to comp.os.msdos.programmer.
  244.  
  245.     - comp.os.ms-windows.programmer.tools and ...misc (formerly part of
  246.       comp.windows.ms.programmer):  Similar to this group, but focus
  247.       on programming for the MS-Windows platform.
  248.  
  249.     - comp.sys.ibm.pc.hardware is for more hardware-oriented discussions
  250.       of the machines that run DOS.
  251.  
  252.     - the various comp.lang.* groups for articles and questions on the
  253.       programming languages.  Caution:  some groups welcome discussions
  254.       that are operating-system dependent or vendor specific; others do
  255.       not.  For example, comp.lang.c is definitely _not_ for questions
  256.       about programming DOS or PC system features, even if the programs
  257.       are written in C.  On the other hand, comp.lang.pascal contains
  258.       much discussion that is specific to Turbo Pascal.
  259.  
  260.     - comp.binaries.ibm.pc.wanted: AFTER you have looked in the other
  261.       groups, this is the place to post a request for a particular
  262.       binary program.
  263.  
  264.     - comp.archives.msdos.announce (moderated) explains how to use the
  265.       archive sites, especially Garbo and Simtel, and lists files
  266.       uploaded to them.  Discussions belong in comp.archives.msdos.d,
  267.       which replaced comp.binaries.ibm.pc.archives in December 1992.
  268.  
  269.     - MSDOS-Ann mailing list, for those who cannot subscribe to the
  270.       comp.archives.msdos.announce newsgroup, lists Simtel and Garbo
  271.       uploads in digest format.  Instructions are downloadable as
  272.         /pc/MSDOSANN.ZIP from Garbo
  273.         pd1:<msdos.info>msdosann.zip from Simtel.
  274.  
  275.     - comp.binaries.ibm.pc.d is for discussions about programs posted in
  276.       comp.binaries.ibm.pc, and only those programs.  This is a good
  277.       place to report bugs in the programs, but not to ask where to find
  278.       them (see cbip.wanted, above).  cbip.d is NOT supposed to be a
  279.       general PC discussion group.
  280.  
  281.     - comp.sources.misc: a moderated group for source code for many
  282.       computer systems.  It tends to get lots of Unix stuff, but you may
  283.       also pick up some DOS-compatible code here.
  284.  
  285.     - alt.sources: an unmoderated group for source code.  Guidelines are
  286.       posted periodically.
  287.  
  288.     - Turbo Vision is a mailing list, not a newsgroup; send email to
  289.       listserv@vtvm1.cc.vt.edu if you want to subscribe.
  290.  
  291. section 2. Compile and link
  292. ===========================
  293.  
  294. Subject:  201. What the heck is "DGROUP > 64K"?
  295.  
  296.     (rev: 18 Apr 1993) DGROUP is a link-time group of data segments, and
  297.     the compiler typically generates code that expects DS to be pointing
  298.     to DGROUP.  (Exception:  Borland's huge model has no DGROUP.)
  299.  
  300.     Here's what goes into DGROUP:
  301.  
  302.     - tiny model (all pointers near):  DGROUP holds the entire program.
  303.  
  304.     - small and medium models (data pointers near):  DGROUP holds all
  305.       globals and static variables including string literals, plus the
  306.       stack and the heap.
  307.  
  308.     - large, compact, and huge models in Microsoft (data pointers far):
  309.       DGROUP holds only initialized globals and static variables
  310.       including string literals, plus the stack and the near heap.
  311.  
  312.     - large and compact models in Borland (data pointers far): DGROUP
  313.       holds initialized and uninitialized globals and static variables
  314.       including string literals, but not the stack or heap.
  315.  
  316.     - huge model in Borland (data pointers far): there is no DGROUP, so
  317.       the 64K limit doesn't apply.
  318.  
  319.     In all of the above, which is to say all six models in Microsoft C
  320.     and all but huge in Borland C, DGROUP is limited to 64K including
  321.     string literals (which are treated as static data).  This limitation
  322.     is due to the Intel CPU's segmented architecture.
  323.  
  324.     See the next Q for possible remedies.
  325.  
  326.     For more information, see topics like "memory models" and "memory
  327.     management" in the index of your compiler manual.  Also see
  328.     ti738.asc, downloadable as part of
  329.         pd1:<msdos.turbo-c>bchelp10.zip at Simtel
  330.         /pc/turbopas/bchelp10.zip at Garbo,
  331.     for an extended general discussion of memory usage in Borland C
  332.     programs, of which much applies to any C compiler in DOS.
  333.  
  334. Subject:  202. How do I fix "automatic data segment exceeds 64K" or
  335.                "stack plus data exceed 64K"?
  336.  
  337.     These messages are a variation of "DGROUP > 64K".  For causes,
  338.     please see the preceding Q.
  339.  
  340.     If you get this error in tiny model, your program is simply too big
  341.     and you must use a different memory model.  If you get this link
  342.     error in models S, C, M, L, or Microsoft's H, there are some things
  343.     you can do.  (This error can't occur in Borland's huge model.)
  344.  
  345.     If you have one or two big global arrays, simply declare them far.
  346.     The compiler takes this to mean that any references to them will use
  347.     32-bit pointers, so they'll be in separate segments and no longer
  348.     part of DGROUP.
  349.  
  350.     Or you can use the /Gt[number] option with Microsoft or -Ff[=size]
  351.     with Borland C++ 2.0 and up.  This will automatically put variables
  352.     above a certain size into their own segments outside of DGROUP.
  353.  
  354.     Yet another option is to change global arrays to far pointers.  Then
  355.     at the beginning of your program, allocate them from the far heap
  356.     (_fmalloc in Microsoft, farmalloc in Borland).
  357.  
  358.     Finally, you can change to huge model (with Borland compilers, not
  359.     Microsoft).  Borland's H model still uses far pointers by default,
  360.     but "sets aside the [64K] limit" and has no DGROUP group, according
  361.     to the BC++ 2.0 Programmer's Guide.  Microsoft's H model does use
  362.     huge data pointers by default but retains DGROUP and its 64K limit,
  363.     so switching to the H model doesn't buy you anything if you have
  364.     DGROUP problems.
  365.  
  366. Subject:  203. Will Borland C code and Microsoft C code link together?
  367.  
  368.     (rev: 15 Aug 1993)  Typically this question is asked by someone who
  369.     owns compiler A and is trying to write code to link with a
  370.     third-party library that was compiled under compiler B.
  371.  
  372.     The answer to the question is, Not in general.  Here are some of the
  373.     reasons:
  374.  
  375.     - "Helper" functions (undocumented functions for stack checking,
  376.       floating-point arithmetic, and operations on longs) differ between
  377.       the two compilers.
  378.  
  379.     - The compilers may embed instructions in the object code that tell
  380.       the linker to look for their own run-time libraries.  You can use
  381.       the linker option that says to ignore such instructions:  /n in
  382.       TLINK, /NOD in the Microsoft linker (the one that comes with the C
  383.       compiler, not the one that used to come with DOS).  But getting
  384.       around this problem will very likely just reveal other problems,
  385.       like different helper functions, that have no easy solution.
  386.  
  387.     Those problems will generate link-time errors.  Others may not show
  388.     up until run time:
  389.  
  390.     - Borland's compact, large, and huge models don't assume DS=SS, but
  391.       Microsoft's do.  The -Fs option on the Borland compiler, or one of
  392.       the /A options on Microsoft, should take care of this problem --
  393.       once you know that's what's going on.
  394.  
  395.     - Check conventions for ordering and packing structure members, and
  396.       for alignment of various types on byte, word, paragraph, or other
  397.       boundaries.  Again, you can generally adjust your code to match if
  398.       you know what conventions were used in compiling the "foreign"
  399.       libraries.
  400.  
  401.     - Check the obvious and make sure that your code was compiled under
  402.       the same memory model as the code you're trying to link with.
  403.       (That's necessary, but no guarantee.  Microsoft and Borland don't
  404.       use exactly the same conventions for segments and groups,
  405.       particularly in the larger memory models.)
  406.  
  407.     That said, there are some circumstances where you can link hybrids.
  408.     Your best chance of success comes if you compile in large model with
  409.     the compiler switch that says to reload DS on entry to each
  410.     function, avoid longs and floating point, use only 16-bit pointers,
  411.     suppress stack checking, and specify all libraries used in the link.
  412.  
  413. Subject:  204. Why did my program bomb at run time with "floating point
  414.                formats not linked"?
  415.  
  416.     First, is that the actual message, or did it say "floating point not
  417.     loaded"?  If it was the latter, see the next Q.
  418.  
  419.     You're probably using a Borland compiler for C or C++ (including
  420.     Turbo C and Turbo C++).  Borland's compilers try to be smart and not
  421.     link in the floating-point (f-p) library unless you need it.  Alas,
  422.     they all get the decision wrong.  One common case is where you don't
  423.     call any f-p functions, but you have %f or other f-p formats in
  424.     scanf/printf calls.  The cure is to call an f-p function, or at
  425.     least force one to be present in the link.
  426.  
  427.     To do that, define this function somewhere in a source file but
  428.     don't call it:
  429.  
  430.         static void forcefloat(float *p)
  431.             { float f = *p; forcefloat(&f); }
  432.  
  433.     It doesn't have to be in the module with the main program, as long
  434.     as it's in a module that will be included in the link.
  435.  
  436.     If you have Borland C++ 3.0, the README file documents a slightly
  437.     less ugly work-around.  Insert these statements in your program:
  438.  
  439.         extern unsigned _floatconvert;
  440.         #pragma extref _floatconvert
  441.  
  442. Subject:  205. Why did my program bomb with "floating point not loaded"?
  443.  
  444.     That is Microsoft C's run-time message when the code requires a
  445.     numeric coprocessor but your computer doesn't have one installed.
  446.  
  447.     If the program is yours, relink it using the xLIBCE or xLIBCA
  448.     library (where x is the memory model).
  449.  
  450. Subject:  206. How can I change the stack size in Borland's C compilers?
  451.  
  452.     In Turbo C, Turbo C++, and Borland C++, you may not find "stack
  453.     size" in the index but the global variable _stklen should be there.
  454.     The manual will instruct you to put a statement like
  455.  
  456.         extern unsigned _stklen = 54321U;
  457.  
  458.     in your code, outside of any function.  You must assign the value
  459.     right in the extern statement; it won't work to assign a value at
  460.     run time.  (The "extern" in this context isn't ANSI C and ought not
  461.     to be required, but the above statement is a direct quote from the
  462.     Library Reference manual of Borland C++ 2.0.)  The linker may give
  463.     you a duplicate symbol warning, which you can ignore.
  464.  
  465. Subject:  207. What's the format of an .OBJ file?
  466.  
  467.     (rev: 24 Sep 1993)
  468.  
  469.     - base .OBJ format:  Intel's document number #121748-001, {8086
  470.       Relocatable Object Module Formats}.  (not verified)
  471.  
  472.     Both Microsoft and Borland have extended the .OBJ format, as has IBM
  473.     for OS/2; and according to the MS-DOS encyclopedia, Microsoft
  474.     doesn't actually use all the listed formats.
  475.  
  476.     - Microsoft-specific .OBJ formats:
  477.  
  478.       * The .OBJ format document dated 14 Dec 1992, a WinHelp file from
  479.         the Microsoft developer's CD-ROM (266K after unzipping), is
  480.         downloadable as /vendor/microsoft/developer-network/ctech/11-9.zip
  481.         from ftp.uu.net. (verified by SB)
  482.  
  483.       * A 45-page article can be found in the {MS-DOS Encyclopedia},
  484.         ISBN 1-55615-049-0 (verified by SB), now out of print.
  485.  
  486.       * "Microsoft Object Module Format (OMF)" Specification, 22 Nov 1991,
  487.         was published by the Microsoft Languages Group.  (not verified)
  488.  
  489.     - Borland-specific .OBJ formats:  Open Architecture Handbook.  The
  490.       Borland Developer's Technical Guide, 1991, no ISBN.  Chapter 2,
  491.       "Object file contents", (pages 27-50) covers the comment records
  492.       sent to the object file by Borland C++ version 3.0 and other
  493.       Borland compilers.  The comment records mostly contain information
  494.       for the Borland debugger. (not verified)
  495.  
  496.     - A "tutorial on the .OBJ format" comes with the VAL experimental
  497.       linker, downloadable as
  498.         pd1:<msdos.pgmutl>val-link.arc at Simtel
  499.         /pc/assembler/linker.zoo at Garbo.
  500.       Despite such different names, those files have the same contents,
  501.       but their contents are dated 18 Feb 1989.  You'd be better off
  502.       with one of the more recent references listed above.
  503.  
  504. Subject:  208. What's the format of an .EXE header?
  505.  
  506.     See pages 349-350 of {PC Magazine} 30 June 1992 (xi:12) for the old
  507.     and new formats.  For a more detailed layout, look under INT 21
  508.     function 4B in Ralf Brown's interrupt list.  Ralf Brown's list
  509.     includes extensions for Borland's TLINK and Borland debugger info.
  510.  
  511.     Among the books that detail formats of executable files are {DOS
  512.     Programmer's Reference: 2d Edition} by Terry Dettman and Jim Kyle,
  513.     ISBN 0-88022-458-4; and {Microsoft MS-DOS Programmer's Reference},
  514.     ISBN 1-55615-329-5.
  515.  
  516. Subject:  209. What's the difference between .COM and .EXE formats?
  517.  
  518.     To oversimplify:  a .COM file is a direct image of core, and an .EXE
  519.     file will undergo some further relocation when it is run (and so it
  520.     begins with a relocation header).  A .COM file is limited to 64K for
  521.     all segments combined, but an .EXE file can have as many segments as
  522.     your linker will handle and be as large as RAM can take.
  523.  
  524.     The actual file extension doesn't matter.  DOS knows that a file
  525.     being loaded is in .EXE format if its first two bytes are MZ or ZM;
  526.     otherwise it is assumed to be in .COM format.  For instance, DR-DOS
  527.     6.0's COMMAND.COM is in .EXE format.
  528.  
  529. section 3. Keyboard
  530. ===================
  531.  
  532. Subject:  301. How can I read a character without echoing it to the
  533.                screen, and without waiting for the user to press the
  534.                Enter key?
  535.  
  536.     The C compilers from Microsoft and Borland offer getch (or getche to
  537.     echo the character); Turbo Pascal has ReadKey.
  538.  
  539.     In other programming languages, load 8 in register AH and execute
  540.     INT 21; AL is returned with the character from standard input
  541.     (possibly redirected).  If you don't want to allow redirection, or
  542.     you want to capture Ctrl-C and other special keys, use INT 16 with
  543.     AH=10; this will return the scan code in AH and ASCII code (if
  544.     possible) in AL, except that AL=E0 with AH nonzero indicates one of
  545.     the grey "extended" keys was pressed.  (If your BIOS doesn't
  546.     support the extended keyboard, use INT 16 function 0 not 10.)
  547.  
  548. Subject:  302. How can I find out whether a character has been typed,
  549.                without waiting for one?
  550.  
  551.     In Turbo Pascal, use KeyPressed.  Both Microsoft C and Turbo C offer
  552.     the kbhit( ) function.  All of these tell you whether a key has been
  553.     pressed.  If no key has been pressed, they return that information
  554.     to your program.  If a keystroke is waiting, they tell your program
  555.     that but leave the key in the input buffer.
  556.  
  557.     You can use the BIOS call, INT 16 function 01 or 11, to check
  558.     whether an actual keystroke is waiting; or the DOS call, INT 21
  559.     function 0B, to check for a keystroke from stdin (subject to
  560.     redirection).  See Ralf Brown's interrupt list.
  561.  
  562. Subject:  303. How can I disable Ctrl-C/Ctrl-Break and/or Ctrl-Alt-Del?
  563.  
  564.     (rev: 11 Sep 1993)  Several utilities are downloadable from
  565.     pd1:<msdos.keyboard> at Simtel.  In that directory, cadel.zip
  566.     contains a TSR (with source code) to disable those keys.  Also,
  567.     keykill.arc contains two utilities:  keykill.com lets you disable up
  568.     to three keys of your choice, and deboot.com changes the boot key to
  569.     leftShift-Alt-Del.
  570.  
  571.     C programmers who simply want to make sure that the user can't
  572.     Ctrl-Break out of their program can use the ANSI-standard signal( )
  573.     function; the Borland compilers also offer ctrlbrk( ) for handling
  574.     Ctrl-Break.  However, if your program uses normal DOS input such as
  575.     getch( ), ^C will appear on the screen when the user presses Ctrl-C
  576.     or Ctrl-Break.  You can avoid the ^C echo for Ctrl-C by using
  577.     _bios_keybrd( ) in MSC or bioskey( ) in BC++; however, Ctrl-Break
  578.     will still terminate the program.
  579.  
  580.     An alternative approach involves programming input at a lower level.
  581.     You can use INT 21 function 7, which allows redirection but doesn't
  582.     echo the ^C (or any other character, for that matter); or use INT 16
  583.     function 0 or 10; or hook INT 9 to discard Ctrl-C and Ctrl-Break
  584.     before the regular BIOS keyboard handler sees them; etc., etc.
  585.  
  586.     You should be aware that Ctrl-C and Ctrl-Break are processed quite
  587.     differently internally.  Ctrl-Break, like all keystrokes, is
  588.     processed by the BIOS code at INT 9 as soon as the user presses the
  589.     keys, even if earlier keys are still in the keyboard buffer:  by
  590.     default the handler at INT 1B is called.  Ctrl-C is not special to
  591.     the BIOS, nor is it special to DOS functions 6 and 7; it _is_
  592.     special to DOS functions 1 and 8 when at the head of the keyboard
  593.     buffer.  You will need to make sure BREAK is OFF to prevent DOS
  594.     polling the keyboard for Ctrl-C during non-keyboard operations.
  595.  
  596.     Some good general references are {Advanced MS-DOS} by Ray Duncan,
  597.     ISBN 1-55615-157-8; {8088 Assembler Language Programming:  The IBM
  598.     PC}, ISBN 0-672-22024-5, by Willen & Krantz; and {COMPUTE!'s Mapping
  599.     the IBM PC}, ISBN 0-942386-92-2.
  600.  
  601. Subject:  304. How can I disable the print screen function?
  602.  
  603.     There are really two print screen functions:  1) print current
  604.     screen snapshot, triggered by PrintScreen or Shift-PrtSc or
  605.     Shift-grey*, and 2) turn on continuous screen echo, started and
  606.     stopped by Ctrl-P or Ctrl-PrtSc.
  607.  
  608.     1) Screen snapshot to printer
  609.  
  610.     The BIOS uses INT 5 for this.  Fortunately, you don't need to mess
  611.     with that interrupt handler.  The standard handler, in BIOSes dated
  612.     December 1982 or later, uses a byte at 0040:0100 (alias 0000:0500)
  613.     to determine whether a print screen is currently in progress.  If it
  614.     is, pressing PrintScreen again is ignored.  So to disable the screen
  615.     snapshot, all you have to do is write a 1 to that byte.  When the
  616.     user presses PrintScreen, the BIOS will think that a print screen is
  617.     already in progress and will ignore the user's keypress.  You can
  618.     re-enable PrintScreen by zeroing the same byte.
  619.  
  620.     Here's some simple code:
  621.  
  622.         void prtsc_allow(int allow) /* 0=disable, nonzero=enable */ {
  623.             unsigned char far* flag = (unsigned char far*)0x00400100UL;
  624.             *flag = (unsigned char)!allow;
  625.         }
  626.  
  627.     2) Continuous echo of screen to printer
  628.  
  629.     If ANSI.SYS is loaded, you can easily disable the continuous echo of
  630.     screen to printer (Ctrl-P or Ctrl-PrtSc).  Just redefine the keys by
  631.     "printing" strings like these to the screen (BASIC print, C printf,
  632.     Pascal Write statements, or ECHO command in batch files):
  633.  
  634.         <27>[0;114;"Ctrl-PrtSc disabled"p
  635.         <27>[16;"^P"p
  636.  
  637.     Change <27> in the above to an Escape character, ASCII 27.
  638.  
  639.     If you haven't installed ANSI.SYS, I (SB) can't offer an easy way to
  640.     disable the echo-screen-to-printer function.  Please send any tested
  641.     solutions to the editor.
  642.  
  643.     Actually, you might not need to disable Ctrl-P and Ctrl-PrtSc.  If
  644.     your only concern is not locking up your machine, when you see the
  645.     "Abort, Retry, Ignore, Fail" prompt just press Ctrl-P again and then
  646.     I.  As an alternative, install one of the many print spoolers that
  647.     intercept printer-status queries and always return "Printer ready".
  648.  
  649. Subject:  305. How can my program turn NumLock (CapsLock, ScrollLock)
  650.                on or off?
  651.  
  652.     First, if you just don't want NumLock turned on when you reboot,
  653.     check your system's setups.  (Use Ctrl-Alt-Enter any time, or press
  654.     a special key like Del at boot time, or run the setup program
  655.     supplied with your system.)  Many systems now have an option in
  656.     setup to turn NumLock off at boot time.
  657.  
  658.     You need to twiddle bit 5, 6, or 4 of location 0040:0017.  Here's
  659.     some code:  lck( ) turns on a lock state, and unlck( ) turns it off.
  660.     (The status lights on some keyboards may not reflect the change.  If
  661.     yours is one, call INT 16 function 2, "get shift status", and that
  662.     may update them.  It will certainly do no harm.)
  663.  
  664.         #define NUM_LOCK  (1 << 5)
  665.         #define CAPS_LOCK (1 << 6)
  666.         #define SCRL_LOCK (1 << 4)
  667.         void lck(int shiftype) {
  668.             char far* kbdstatus = (char far*)0x00400017UL;
  669.             *kbdstatus |= (char)shiftype;
  670.         }
  671.         void unlck(int shiftype) {
  672.             char far* kbdstatus = (char far*)0x00400017UL;
  673.             *kbdstatus &= ~(char)shiftype;
  674.         }
  675.  
  676. Subject:  306. How can I speed up the keyboard's auto-repeat?
  677.  
  678.     The keyboard speed has two components: delay (before a key that you
  679.     hold down starts repeating) and typematic rate (the speed once the
  680.     key starts repeating).  Most BIOSes since 1986 let software change
  681.     the delay and typematic rate by calling INT 16 function 3, "set
  682.     typematic rate and delay"; see Ralf Brown's interrupt list.  If you
  683.     have DOS 4.0 or later, you can use the MODE CON command that you'll
  684.     find in your DOS manual.
  685.  
  686.     On 83-key keyboards (mostly XTs), the delay and typematic rate can't
  687.     easily be changed.  According to the {PC Magazine} of 15 Jan 1991,
  688.     page 409, to adjust the typematic rate you need "a memory-resident
  689.     program which simply '[watches]' the keyboard to see if you're
  690.     holding down a key ... and after a certain time [starts] stuffing
  691.     extra copies of the held-down key into the buffer."  No source code
  692.     is given in that issue; but the QUICKEYS utility that {PC} published
  693.     in 1986 does this sort of watching (not verified); source and object
  694.     code are downloadable in pd1:<msdos.pcmag>vol5n05.arc from Simtel.
  695.  
  696. Subject:  307. What is the SysRq key for?
  697.  
  698.     There is no standard use for the key.  The BIOS keyboard routines in
  699.     INT 16 simply ignore it; therefore so do the DOS input routines in
  700.     INT 21 as well as the keyboard routines in libraries supplied with
  701.     high-level languages.
  702.  
  703.     When you press or release a key, the keyboard triggers hardware line
  704.     IRQ1, and the CPU calls INT 9.  INT 9 reads the scan code from the
  705.     keyboard and the shift states from the BIOS data area.
  706.  
  707.     What happens next depends on whether your PC's BIOS supports an
  708.     enhanced keyboard (101 or 102 keys).  If so, INT 9 calls INT 15
  709.     function 4F to translate the scan code.  If the translated scan code
  710.     is 54 hex (for the SysRq key) then INT 9 calls INT 15 function 85
  711.     and doesn't put the keystroke into the keyboard buffer.  The default
  712.     handler of that function does nothing and simply returns.  (If your
  713.     PC has an older BIOS that doesn't support the extended keyboards,
  714.     INT 15 function 4F is not called.  Early ATs have 84-key keyboards,
  715.     so their BIOS calls INT 15 function 85 but nor 4F.)
  716.  
  717.     Thus your program is free to use SysRq for its own purposes, but at
  718.     the cost of some programming.  You could hook INT 9, but it's
  719.     probably easier to hook INT 15 function 85, which is called when
  720.     SysRq is pressed or released.
  721.  
  722. Subject:  308. How can my program tell what kind of keyboard is on the
  723.                system?
  724.  
  725.     Ralf Brown's Interrupt List includes MEMORY.LST, a detailed
  726.     breakdown by Robin Walker of the contents of the BIOS system block
  727.     that starts at 0040:0000.  Bit 4 of byte 0040:0096 is "1=enhanced
  728.     keyboard installed".  C code to test the keyboard type:
  729.         char far *kbd_stat_byte3 = (char far *)0x00400096UL;
  730.         if (0x10 & *kbd_stat_byte3)
  731.             /* 101- or 102-key keyboard is installed */
  732.  
  733.     {PC Magazine} 15 Jan 1991 issue suggests on page 412 that "for some
  734.     clones [the above test] is not foolproof".  If you use this method
  735.     in your program you should provide the user some way to override
  736.     this test, or at least some way to tell your program to assume a
  737.     non-enhanced keyboard.  The article suggests a different approach to
  738.     determining the type of keyboard.
  739.  
  740. Subject:  309. How can I tell if input, output, or stderr has been
  741.                redirected?
  742.  
  743.     (rev: 24 Sep 1993)  Normally, input and output are associated with
  744.     the console (i.e., with the keyboard and the screen, respectively).
  745.     If either is not, you know that it has been redirected.  Some source
  746.     code to check this is available at the usual archive sites.
  747.  
  748.     If you program in Turbo Pascal, you'll want this downloadable
  749.     collection of Turbo Pascal units:
  750.         /pc/ts/tspa33*.zip at Garbo
  751.         pd1:<msdos.turbopas>tspa33*.zip at Simtel.
  752.     (where the * is 70, 60, 55, 50, or 40 for Turbo Pascal 7.0, 6.0,
  753.     5.5, 5.0, or 4.0 respectively.)  Source code is not included.  Also
  754.     see the downloadable Frequently Asked Questions files by Timo Salmi:
  755.         /pc/ts/tsfaqp15.zip at Garbo
  756.         pd1:<msdos.info>tsfaqp15.zip at Simtel.
  757.  
  758.     If you program in C, use isatty( ) if your implementation has it.
  759.     Otherwise, pd1:<msdos.sysutl>is_con10.zip is downloadable from
  760.     Simtel; it includes source code.
  761.  
  762.     Good references for the principles are {PC Magazine} 16 Apr 1991
  763.     (x:7) pg 374; Ray Duncan's {Advanced MS-DOS}, ISBN 1-55615-157-8, or
  764.     Ralf Brown's interrupt list for INT 21 function 4400; and Terry
  765.     Dettman and Jim Kyle's {DOS Programmer's Reference:  2d edition},
  766.     ISBN 0-88022-458-4, pp 602-603.
  767.  
  768. Subject:  310. How can I increase the size of the keyboard buffer?
  769.  
  770.     (new: 20 June 1993)  SB tested only one of the many available device
  771.     drivers that do this, namely BUF160, which extends the keyboard
  772.     buffer to 160 characters.  It performed flawlessly for two years
  773.     with MS-DOS 5 and Windows 3.1.  It's downloadable as
  774.         pd1:<msdos.keyboard>buf160_6.zip at Simtel
  775.         /pc/keyboard/buf160_6.zip at Garbo.
  776.  
  777. Subject:  311. How can I stuff characters into the keyboard buffer?
  778.  
  779.     (new: 15 Aug 1993)  If your computer has an enhanced keyboard (see
  780.     "How can my program tell what kind of keyboard is on the system?",
  781.     above), then put the scan code in CH, the ASCII character in CL, 5
  782.     in AH, and execute INT 16.  The return in AL is 0 for success or 1
  783.     for buffer full.
  784.  
  785. (continued in part 3)
  786. -- 
  787. Stan Brown, Oak Road Systems                    brown@Ncoast.ORG
  788.  
  789. Can't find FAQ lists?  ftp to 'rtfm.mit.edu' and look in /pub/usenet
  790. (or email me >>> with valid reply-to address <<< for instructions).
  791.  
  792.