Hi!

- serial.asm, fatfs.c, dsk.c, inthndlr.c: log info not moved out (or moved
  not completely).

- initclk.c: why there Patv copyright and DOS-C mention if this is new file?

- Was:

______________O\_/_________________________________\_/O______________
#ifdef MAIN
#ifdef VERSION_STRINGS
...
#endif
#endif
_____________________________________________________________________
              O/~\                                 /~\O

Can be:

______________O\_/_________________________________\_/O______________
#if defined(MAIN) && defined(VERSION_STRINGS)
...
#endif
_____________________________________________________________________
              O/~\                                 /~\O

- chario.c. Was:

______________O\_/_________________________________\_/O______________
  unsigned char chr = (unsigned char)c;
[...]
  c = (int)BinaryCharIO(dev, 1, &chr, C_OUTPUT);
  if (c < 0)
    return c;
  else
    return chr;
_____________________________________________________________________
              O/~\                                 /~\O

Can be:

______________O\_/_________________________________\_/O______________
  unsigned char chr = c;
[...]
  c = BinaryCharIO(dev, 1, &chr, C_OUTPUT);
  if (c >= 0) c = chr;
  return c;
_____________________________________________________________________
              O/~\                                 /~\O

- config.c. Was:

______________O\_/_________________________________\_/O______________
  BYTE FAR *tmplpBase = lpBase;
  unsigned wantedbuffers = anzBuffers;

  if (anzBuffers < 0)
  {
    wantedbuffers = anzBuffers = -anzBuffers;
  }
  else if (HMAState == HMA_DONE)
  {
    anzBuffers = (0xfff0 - HMAFree) / sizeof(struct buffer);
  }

  anzBuffers = max(anzBuffers, 6);
  if (anzBuffers > 99)
  {
    printf("BUFFERS=%u not supported, reducing to 99\n", anzBuffers);
    anzBuffers = 99;
  }
[...]
  if (HMAState == HMA_NONE || HMAState == HMA_REQ)
    lpTop = lpBase = lpTop - (anzBuffers * sizeof(struct buffer) + 0xf);

  firstbuf = ConfigAlloc(sizeof(struct buffer) * anzBuffers);
  pbuffer = firstbuf;
[...]
  pbuffer->b_prev = FP_OFF(pbuffer + (anzBuffers-1));
  for (i = 1; i < anzBuffers; ++i)
  {
    if (i == wantedbuffers)
    {
      firstAvailableBuf = pbuffer;
    }
    pbuffer->b_next = FP_OFF(pbuffer + 1);
    pbuffer++;
    pbuffer->b_prev = FP_OFF(pbuffer - 1);
  }
  pbuffer->b_next = FP_OFF(pbuffer - (anzBuffers-1));
[...]
  if (HMAState == HMA_NONE || HMAState == HMA_REQ)
    lpBase = tmplpBase;
_____________________________________________________________________
              O/~\                                 /~\O

Can be:

______________O\_/_________________________________\_/O______________
>  BYTE FAR *tmplpBase;
>  unsigned wantedbuffers;

  if (anzBuffers < 0)
  {
    wantedbuffers = anzBuffers = -anzBuffers;
  }
  else if (HMAState == HMA_DONE)
  {
>    wantedbuffers = anzBuffers;
    anzBuffers = (0xfff0 - HMAFree) / sizeof(struct buffer);
  }

>  if (anzBuffers < 6) anzBuffers = 6;
  if (anzBuffers > 99)
  {
    printf("BUFFERS=%u not supported, reducing to 99\n", anzBuffers);
    anzBuffers = 99;
  }
[...]
  if (HMAState == HMA_NONE || HMAState == HMA_REQ) {
>    tmplpBase = lpBase;
    lpTop = lpBase = lpTop - (anzBuffers * sizeof(struct buffer) + 0xf);
  }

>  pbuffer =
  firstbuf = ConfigAlloc(sizeof(struct buffer) * anzBuffers);
[...]
>  anzBuffers--;
>  pbuffer->b_prev = FP_OFF(pbuffer + anzBuffers);
>  for (i = 1; i <= anzBuffers; i++) {
[...]
  }
[...]
>        printf ... anzBuffers+1
[...]
>  pbuffer->b_next = FP_OFF(pbuffer - anzBuffers);
_____________________________________________________________________
              O/~\                                 /~\O

- sysclk. Was:

______________O\_/_________________________________\_/O______________
        /* Fix year by looping through each year, subtracting   */
        /* the appropriate number of days for that year.        */
        for (Year = 1980, Day = clk.clkDays;;)
        {
          pdays = is_leap_year_monthdays(Year);
          if (Day >= pdays[12])
          {
            ++Year;
            Day -= pdays[12];
          }
          else
            break;
        }

        /* Day contains the days left and count the number of   */
        /* days for that year.  Use this to index the table.    */
        for (Month = 1; Month < 13; ++Month)
        {
          if (pdays[Month] > Day)
          {
            Day = Day - pdays[Month - 1] + 1;
            break;
          }
        }
[...]
      }
      return S_DONE;

    case C_OFLUSH:
    case C_IFLUSH:
      return S_DONE;
_____________________________________________________________________
              O/~\                                 /~\O

Can be:

______________O\_/_________________________________\_/O______________
        /* Calculate year by looping through each year and      */
        /* subtracting the number of days for that year.        */
        Year = 1980, Day = clk.clkDays;
        for (;;) {
          pdays = is_leap_year_monthdays(Year);
          if (Day < pdays[12]) break;
          Day -= pdays[12], Year++;
        }

        /* Day contains the days left in the year.              */
        for (Month = 1; Day >= pdays[1]; pdays++, Month++) ;
        Day -= pdays [0] - 1;
[...]
      }

    case C_OFLUSH:
    case C_IFLUSH:
      return S_DONE;
_____________________________________________________________________
              O/~\                                 /~\O

- fatfs.c. Was:

______________O\_/_________________________________\_/O______________
#ifdef DISPLAY_GETBLOCK
  printf("map_cluster: current %lu, offset %lu, diff=%lu ",
         (ULONG)fnp->f_cluster_offset, fnp->f_offset,
         fnp->f_offset - fnp->f_cluster_offset);
#endif
_____________________________________________________________________
              O/~\                                 /~\O

Should be (to ensure that formatting flags not desyncronized with
expression types):

______________O\_/_________________________________\_/O______________
#ifdef DISPLAY_GETBLOCK
  printf("map_cluster: current %lu, offset %lu, diff=%lu ",
         (ULONG)fnp->f_cluster_offset, (ULONG)fnp->f_offset,
         (ULONG)(fnp->f_offset - fnp->f_cluster_offset));
#endif
_____________________________________________________________________
              O/~\                                 /~\O

- blockio.c. Was:

______________O\_/_________________________________\_/O______________
  /* insert bp between firstbp and firstbp->b_prev */
  bp->b_prev = bufptr(firstbp)->b_prev;
  bp->b_next = firstbp;
  b_next(bp)->b_prev = FP_OFF(bp);
  b_prev(bp)->b_next = FP_OFF(bp);
_____________________________________________________________________
              O/~\                                 /~\O

Can be (note, I remove `b_' prefix for readability):

______________O\_/_________________________________\_/O______________
  /* insert bp between firstbp->b_prev and firstbp */
  bufptr(bp->prev = bufptr(firstbp)->prev)->b_next = FP_OFF(bp);
  bufptr(bp->next = firstbp)              ->b_prev = FP_OFF(bp);
_____________________________________________________________________
              O/~\                                 /~\O

- inthndlr.c. There present explicit "extern AllocateHMASpace()". Next, was:

______________O\_/_________________________________\_/O______________
  UWORD function = r.ax & 0xff;
[...]
  if ((r.ax & 0xff00) == 0x4a00)
  {
    size_t wantedBytes = r.bx;

    r.bx = 0;
    r.es = FP_SEG(firstAvailableBuf);
    r.di = FP_OFF(firstAvailableBuf);
    if (FP_SEG(firstAvailableBuf) != 0xffff)
    {
      return;
    }

    if (r.ax == 0x4a01)
    {
      r.bx = 0 - FP_OFF(firstAvailableBuf);
      return;
    }

    if (r.ax == 0x4a02)
    {
      if (wantedBytes > 0 - FP_OFF(firstAvailableBuf))
      {
        r.bx = 0;
        return;
      }
      AllocateHMASpace(FP_OFF(firstAvailableBuf),
                       FP_OFF(firstAvailableBuf)+wantedBytes);
      firstAvailableBuf += wantedBytes;

      return;
    }
  }
_____________________________________________________________________
              O/~\                                 /~\O

Should be (see the `r.a.b.l', `r.b.x', etc):

______________O\_/_________________________________\_/O______________
  UBYTE func = r.a.b.l;
[...]
  if (r.a.b.h == 0x4A) {
    size_t wantedBytes = r.b.x;

    r.b.x = 0;
    r.es = FP_SEG(firstAvailableBuf);
    r.di = FP_OFF(firstAvailableBuf);
    if (r.es != 0xFFFF)
      return;

    if (func == 1) {
      r.b.x = -r.di; /*!!! WARNING: shouldn't be optimized out !!!*/
      return;
    }

    if (func == 2) {
      if (wantedBytes > -r.di)
        return;
      AllocateHMASpace(r.di, r.di + wantedBytes);
      firstAvailableBuf += wantedBytes;
      return;
  } }
_____________________________________________________________________
              O/~\                                 /~\O

Also, looks like there may be later introduced bug, if you by some reason
pass to this function also AX==4A16 (under `CASE func=0x16' used BX).

On the other side, nonhandled functions (filtered by "if (func > 0x31)") may
be filtered above, in INT2F.ASM.

- initclk.c/sysclk.c:
  - in both not optimized BCDToByte() and ByteToBCD().

- initclk.c:
  - "regsT.flags = 0;" clears beside CF also IF flag, BUT looks like
    init_call_intr() isn't restores loads flags before INT instruction!
  - Init_clk_driver() should look like:

______________O\_/_________________________________\_/O______________
  iregs rtm, rdt, r;

  rtm.a.b.h = 0x02;
  rtm.d.x = rtm.c.x = 0;
  rtm.flags = 0;                /* ??? */
  init_call_intr(0x1a, &rtm);
  if ((rtm.flags & CF_FLAG) || (rtm.c.x | rtm.d.x) == 0)
        return;                 /* error */

  rdt.a.b.h = 0x04;
  rdt.d.x = rdt.c.x = 0;
  rdt.flags = 0;                /* ??? */
  init_call_intr(0x1a, &rdt);
  if ((rdt.flags & CF_FLAG) || (rdt.c.x | rdt.d.x) == 0)
        return;
_____________________________________________________________________
              O/~\                                 /~\O

But, CF=1 may mean "try retry later", so "return" may/should be replaced by
"continue" inside loop with 2-3 iterations. Also, I suggest, that (CX|DX)==0
may/should be checked only after first function.

     And again there appear question of midnigt timer wrapping: if between
two above calls date changed, then you get end of new day instead its start
inside DOS timer. This mean that code should look like:

loop:   INT 1A/4; if CF or (CX|DX) == 0 then continue
        INT 1A/2; if CF then continue
        INT 1A/4; if CF=0 and date not changed then break
        loop (2-5 iterations)

Moreover, to decrease space for registers, you may insert DOS calls right
after checking error (this will then require space only for ONE registers
structure instead THREE).

==^================================================================
This email was sent to: [email protected]

EASY UNSUBSCRIBE click here: http://topica.com/u/?b1ddyi.b3hwCs.YXJjaGl2
Or send an email to: [EMAIL PROTECTED]

T O P I C A -- Register now to manage your mail!
http://www.topica.com/partner/tag02/register
==^================================================================

Reply via email to