[net.micro.atari16] Bug in GEMDOS

wampler@unmvax.UUCP (Bruce Wampler) (10/07/86)

   My previous posting was correct about the cause of the TVX bug, but
wrong in the fix.  Since this seems to be a general bug/feature of
GEMDOS, my solution might be of general interest.

    There is some incorrect interaction between GEMDOS function 7
(unechoed keyboard input, probably the others too) and GEMDOS
function 9 (print a line, probably the other character at a time, too.).

You can write characters faster to GEMDOS 9 than it can display them
on the screen.  If you are doing this while the user has the
key clamped down at a very fast repeat rate, soon everything
will die.  The bug seems to be that GEMDOS 9 doesn't bother to
check the conout status to see that it can take more characters.

My solution was to go to the bios directly (trap 13), passing up the GEMDOS
functions.  Character output should be done like this:

 char_out(output_char) char output_char;
  {
    while (!bios(8,2))		/* check output status */
	if (bios(1,2))		/* check if input waiting */
	    save_input_char(bios(2,2)); /* do SOMETHING with input chr */
    bios(3,2,output_char);	/* now safe to write char */
  }

Apparently, GEMDOS 9 doesn't do the output status check.  Maybe
the other GEMDOS character output routines do, but I didn't check
them.  (For anyone interested, the REAL fix to TVX is to change
ttwtln to use ttwt, and put the above fix into dispch, and throw
away the extra input characters.)
--
Dr. Bruce E. Wampler
University of New Mexico
Department of Computer Science
Albuquerque, NM 87131

..{ucbvax | seismo!gatech | ihnp4!lanl}!unmvax!wampler

dyer@atari.UUcp (Landon Dyer) (10/10/86)

The real culprit is what I would refer to as a "semi-circular" buffer
in GEMDOS's character I/O routines.  When you read with Cconin(), you
must read ALL the characters that are available before using Cconout()
or Cconws().  If you don't, the buffer will overflow and cause a
crash.  (The program at the end of this posting demonstrates the
problem quite dramatically).

The BIOS has no such problem.  My philosophy is (and always has
been) to avoid the GEMDOS console, aux and printer functions, and
go directly to the BIOS.

>  /*
>   *  holdkey --- semi-circular buffer test
>   *
>   *  Test:
>   *	Run it.  Hold down RETURN until auto-repeat starts.  Keep
>   *	holding RETURN down.  The system should crash (the exact
>   *	exception varies).
>   *
>   *  Status:
>   *	Fixed.
>   *
>   */
>  #include <osbind.h>
>  
>  main()
>  {
>    for (;;)
>      {
>        Cconws("Keep holding RETURN down.  A crash should happen soon.\r\n");
>        Cconin();
>      }
>  }

-- 

-Landon Dyer, Atari Corp.		        {sun,lll-lcc,imagen}!atari!dyer

/-----------------------------------------------\
| The views represented here do not necessarily | "If Business is War, then
| reflect those of Atari Corp., or even my own. |  I'm a Prisoner of Business!"
\-----------------------------------------------/