--- Begin Message ---
diff -ruNp old/kernel/blockio.c new/kernel/blockio.c
--- old/kernel/blockio.c        2004-04-13 13:11:08.000000000 +0000
+++ new/kernel/blockio.c        2004-04-24 03:19:32.000000000 +0000
@@ -469,35 +469,45 @@ UWORD dskxfer(COUNT dsk, ULONG blkno, VO
 
 }
 
-/*
-       this removes any (additionally allocated) buffers 
-       from the HMA buffer chain, because they get allocated to the 'user'
-*/     
-     
-void AllocateHMASpace (size_t lowbuffer, size_t highbuffer)
+/* this removes any (additionally allocated) buffers from the
+   HMA buffer chain, because they get allocated to the 'user'.
+   There assumed that:
+       LoL_nbuffers > 0
+       not all buffers inside [start..last] area
+*/
+
+#define b_(ofs) ((struct buffer FAR*)MK_FP(/*HMASEG*/0xFFFF, ofs))
+
+void freeHMAbuffers (ofs_t startarea, ofs_t nextarea)
 {
-  REG struct buffer FAR *bp = firstbuf;
-  int n;
+  ofs_t buf;
 
-  if (FP_SEG(bp) != 0xffff)
+  if (FP_SEG (firstbuf) != /*HMASEG*/0xFFFF)
     return;
 
-  n = LoL_nbuffers;
-  do
+  buf = b_(FP_OFF (firstbuf))->b_next;
+  for (;;)
   {
-    /* check if buffer intersects with requested area                  */
-    if (FP_OFF(bp) < highbuffer && FP_OFF(bp+1) > lowbuffer)
+    ofs_t next = b_(buf)->b_next;
+
+    /* check if buffer intersects with requested area                  */
+    if (buf < nextarea && buf + sizeof(struct buffer) > startarea)
     {
-      flush1(bp);
-      /* unlink bp from buffer chain */
+      flush1 (b_(buf));
 
-      b_prev(bp)->b_next = bp->b_next;
-      b_next(bp)->b_prev = bp->b_prev;
-      if (FP_OFF(bp) == FP_OFF(firstbuf))
-        firstbuf = b_next(bp);
+      /* unlink buffer from chain                                      */
       LoL_nbuffers--;
+      b_(b_(next)->b_prev = b_(buf)->b_prev)->b_next = next;
+
+      if (buf == FP_OFF (firstbuf))
+      {
+       *(UWORD*)&firstbuf = next;
+       break;
+      }
     }
-    bp = b_next(bp);
+
+    if (buf == FP_OFF (firstbuf))
+      break;
+    buf = next;
   }
-  while (--n);
 }
diff -ruNp old/kernel/config.c new/kernel/config.c
--- old/kernel/config.c 2004-04-14 16:04:04.000000000 +0000
+++ new/kernel/config.c 2004-04-24 12:35:40.000000000 +0000
@@ -43,6 +43,18 @@ static BYTE *RcsId =
 #endif
 #define para2far(seg) ((mcb FAR *)MK_FP((seg), 0))
 
+typedef UWORD ofs_t;
+typedef UWORD seg_t;
+
+#if __TURBOC__ > 0x202
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type _seg*) (seg))
+#else
+# define _seg FAR
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type FAR*) MK_FP (seg, 0))
+#endif
+
 /**
   Menu selection bar struct:
   x pos, ypos, string
@@ -125,6 +137,9 @@ static UBYTE ErrorAlreadyPrinted[128] BS
 char master_env[128] BSS_INIT({0});
 static char *envp = master_env;
 
+static char init[NAMEMAX] = "command.com";
+static char inittail[NAMEMAX] = " /P /E:256\r\n";
+
 struct config Config = {
   0,
   NUMBUFF,
@@ -132,8 +147,8 @@ struct config Config = {
   0,
   NFCBS,
   0,
-  "command.com",
-  " /P /E:256\r\n",
+  init,
+  inittail,
   NLAST,
   0,
   NSTACKS,
@@ -267,7 +282,6 @@ STATIC struct table commands[] = {
 
   {"BREAK", 1, CfgBreak},
   {"BUFFERS", 1, Config_Buffers},
-  {"COMMAND", 1, InitPgm},
   {"COUNTRY", 1, Country},
   {"DOS", 1, Dosmem},
   {"DOSDATA", 1, DosData},
@@ -480,16 +494,13 @@ void PostConfig(void)
 VOID configDone(VOID)
 {
   if (UmbState == 1)
-    para2far(base_seg)->m_type = MCB_LAST;
+    FP_SEG_PTR(mcb, base_seg)->m_type = MCB_LAST;
 
   if (HMAState != HMA_DONE)
   {
-    mcb FAR *p;
-    unsigned short kernel_seg;
-    unsigned short hma_paras = (HMAFree+0xf)/16;
-
-    allocmem(hma_paras, &kernel_seg);
-    p = para2far(kernel_seg - 1);
+    unsigned short hma_paras = (HMAFree + 15) / 16;
+    unsigned short kernel_seg = allocmem(hma_paras);
+    mcb _seg *p = FP_SEG_PTR(mcb, kernel_seg - 1);
 
     p->m_name[0] = 'S';
     p->m_name[1] = 'C';
@@ -498,9 +509,7 @@ VOID configDone(VOID)
     DebugPrintf(("HMA not available, moving text to %x\n", kernel_seg));
     MoveKernel(kernel_seg);
 
-    kernel_seg += hma_paras + 1;
-
-    DebugPrintf(("kernel is low, start alloc at %x", kernel_seg));
+    DebugPrintf(("kernel is low, start alloc at %x", kernel_seg + hma_paras + 1));
   }
 
   /* The standard handles should be reopened here, because
@@ -1237,12 +1246,6 @@ STATIC VOID InitPgmHigh(BYTE * pLine)
 
 STATIC VOID InitPgm(BYTE * pLine)
 {
-  static char init[NAMEMAX];
-  static char inittail[NAMEMAX];
-
-  Config.cfgInit = init;
-  Config.cfgInitTail = inittail;
-
   /* Get the string argument that represents the new init pgm     */
   pLine = GetStringArg(pLine, Config.cfgInit);
 
@@ -1684,47 +1687,44 @@ STATIC void config_init_buffers(int want
   struct buffer FAR *pbuffer;
   unsigned buffers = 0;
 
-  /* fill HMA with buffers if BUFFERS count >=0 and DOS in HMA        */
+  /* fill HMA with buffers if BUFFERS count >=0 and DOS in HMA          */
   if (wantedbuffers < 0)
     wantedbuffers = -wantedbuffers;
   else if (HMAState == HMA_DONE)
     buffers = (0xfff0 - HMAFree) / sizeof(struct buffer);
 
-  if (wantedbuffers < 6)         /* min 6 buffers                     */
+  if (wantedbuffers < 6)                /* min 6 buffers                */
     wantedbuffers = 6;
-  if (wantedbuffers > 99)        /* max 99 buffers                    */
+  if (wantedbuffers > 99)               /* max 99 buffers               */
   {
     printf("BUFFERS=%u not supported, reducing to 99\n", wantedbuffers);
     wantedbuffers = 99;
   }
-  if (wantedbuffers > buffers)   /* more specified than available -> get em */
+  if (buffers < wantedbuffers)          /* not less than requested      */
     buffers = wantedbuffers;
 
   LoL->nbuffers = buffers;
   LoL->inforecptr = &LoL->firstbuf;
   {
     size_t bytes = sizeof(struct buffer) * buffers;
-    pbuffer = HMAalloc(bytes);
-
-    if (pbuffer == NULL)
+    if ((pbuffer = HMAalloc(bytes)) == NULL)
     {
       pbuffer = KernelAlloc(bytes, 'B', 0);
-      if (HMAState == HMA_DONE)
-        firstAvailableBuf = MK_FP(0xffff, HMAFree);
+      HMAuserarea = HMAState == HMA_DONE ? HMAFree : 0xffff;
     }
     else
     {
       LoL->bufloc = LOC_HMA;
       LoL->deblock_buf = KernelAlloc(SEC_SIZE, 'B', 0);
-      /* space in HMA beyond requested buffers available as user space */
-      firstAvailableBuf = pbuffer + wantedbuffers;
+
+      /* space in HMA beyond requested buffers available as user space  */
+      HMAuserarea = FP_OFF (pbuffer + wantedbuffers);
     }
   }
-
   LoL->firstbuf = pbuffer;
 
-  DebugPrintf(("init_buffers (size %u) at", sizeof(struct buffer)));
-  DebugPrintf((" (%p)", LoL->firstbuf));
+  DebugPrintf(("init_buffers (size %u) at (%p)",
+               sizeof(struct buffer), pbuffer));
 
   buffers--;
   pbuffer->b_prev = FP_OFF(pbuffer + buffers);
@@ -1735,20 +1735,13 @@ STATIC void config_init_buffers(int want
       pbuffer->b_next = FP_OFF(pbuffer + 1);
       pbuffer++;
       pbuffer->b_prev = FP_OFF(pbuffer - 1);
-    }
-    while (--i);
+    } while (--i);
   }
   pbuffer->b_next = FP_OFF(pbuffer - buffers);
 
-    /* now, we can have quite some buffers in HMA
-       -- up to 50 for KE38616.
-       so we fill the HMA with buffers
-       but not if the BUFFERS count is negative ;-)
-     */
-
   DebugPrintf((" done\n"));
 
-  if (FP_SEG(pbuffer) == 0xffff)
+  if (FP_SEG(pbuffer) == /*HMASEG*/0xFFFF)
   {
     buffers++;
     printf("Kernel: allocated %d Diskbuffers = %u Bytes in HMA\n",
@@ -2592,7 +2585,7 @@ VOID DoInstall(void)
   r.b.b.l = 0x02;                          /*low memory, last fit                     
 */
   init_call_intr(0x21, &r);
 
-  allocmem(((unsigned)_init_end + ebda_size + 15) / 16, &installMemory);
+  installMemory = allocmem(((unsigned)_init_end + ebda_size + 15) / 16);
 
   InstallPrintf(("allocated memory at %x\n",installMemory));
 
diff -ruNp old/kernel/globals.h new/kernel/globals.h
--- old/kernel/globals.h        2004-04-09 15:47:20.000000000 +0000
+++ new/kernel/globals.h        2004-04-24 07:06:32.000000000 +0000
@@ -250,7 +250,7 @@ FAR *ASM firstbuf;                  /* h
 enum {LOC_CONV=0, LOC_HMA=1};
 extern unsigned char ASM bufloc;    /* 0=conv, 1=HMA                        */
 extern void far * ASM deblock_buf;  /* pointer to workspace buffer      */
-GLOBAL char FAR *firstAvailableBuf;
+GLOBAL size_t HMAuserarea;
 extern struct cds FAR * ASM CDSp;   /* Current Directory Structure          */
 extern
 struct cds FAR * ASM current_ldt;
@@ -359,8 +359,7 @@ extern UWORD ASM f_nodes_cnt;   /* numbe
 
 /* Process related functions - not under automatic generation.  */
 /* Typically, these are in ".asm" files.                        */
-VOID ASMCFUNC FAR cpm_entry(VOID)
-/*INRPT FAR handle_break(VOID) */ ;
+VOID ASMCFUNC FAR cpm_entry(VOID);
 VOID enable(VOID), disable(VOID);
 COUNT ASMCFUNC
     CriticalError(COUNT nFlag, COUNT nDrive, COUNT nError,
@@ -371,7 +370,6 @@ VOID ASMCFUNC FAR CharMapSrvc(VOID);
 VOID ASMCFUNC FAR set_stack(VOID);
 VOID ASMCFUNC FAR restore_stack(VOID);
 #endif
-/*VOID INRPT FAR handle_break(VOID); */
 
 ULONG ASMPASCAL ReadPCClock(VOID);
 VOID ASMPASCAL WriteATClock(BYTE *, BYTE, BYTE, BYTE);
diff -ruNp old/kernel/init-mod.h new/kernel/init-mod.h
--- old/kernel/init-mod.h       2004-04-14 09:41:28.000000000 +0000
+++ new/kernel/init-mod.h       2004-04-24 07:23:16.000000000 +0000
@@ -157,10 +157,10 @@ unsigned ASMPASCAL init_call_intr(int nr
 unsigned ASMPASCAL read(int fd, void *buf, unsigned count);
 int ASMPASCAL open(const char *pathname, int flags);
 int ASMPASCAL close(int fd);
-int ASMPASCAL dup2(int oldfdk, int newfd);
-int ASMPASCAL allocmem(UWORD size, seg * segp);
+int ASMPASCAL dup2(int oldfd, int newfd);
+seg ASMPASCAL allocmem(UWORD size);
 void ASMPASCAL init_PSPSet(seg psp_seg);
-int ASMPASCAL init_DosExec(int mode, exec_blk * ep, char * lp);
+int ASMPASCAL init_DosExec(int mode, exec_blk * ep, const char * lp);
 int ASMPASCAL init_setdrive(int drive);
 int ASMPASCAL init_switchar(int chr);
 void ASMPASCAL keycheck(void);
@@ -171,7 +171,7 @@ void ASMPASCAL set_DTA(void far *dta);
 #pragma aux (pascal) init_DosOpen modify exact [ax bx dx]
 #pragma aux (pascal) close modify exact [ax bx]
 #pragma aux (pascal) dup2 modify exact [ax bx cx]
-#pragma aux (pascal) allocmem modify exact [ax bx dx]
+#pragma aux (pascal) allocmem modify exact [ax bx]
 #pragma aux (pascal) init_PSPSet modify exact [ax bx]
 #pragma aux (pascal) init_DosExec modify exact [ax bx dx es]
 #pragma aux (pascal) init_setdrive modify exact [ax bx dx]
@@ -238,7 +238,7 @@ extern struct lol FAR *LoL;
 
 extern struct dhdr DOSTEXTFAR ASM blk_dev; /* Block device (Disk) driver           */
 
-extern struct buffer FAR *DOSFAR firstAvailableBuf; /* first 'available' buffer   */
+extern size_t DOSFAR HMAuserarea;
 extern struct lol ASM FAR DATASTART;
 
 extern BYTE DOSFAR ASM _HMATextAvailable,    /* first byte of available CODE area    
*/
@@ -306,4 +306,3 @@ ULONG ASMCFUNC FAR MULULUL(ULONG mul1, U
 ULONG ASMCFUNC FAR DIVULUS(ULONG mul1, UWORD mul2);     /* DIVide ULong by UShort */
 ULONG ASMCFUNC FAR DIVMODULUS(ULONG mul1, UWORD mul2, UWORD * rem);     /* DIVide 
ULong by UShort */
 #endif
-
diff -ruNp old/kernel/inthndlr.c new/kernel/inthndlr.c
--- old/kernel/inthndlr.c       2004-04-14 17:40:50.000000000 +0000
+++ new/kernel/inthndlr.c       2004-04-24 07:22:38.000000000 +0000
@@ -233,10 +233,10 @@ int int21_fat32(lregs *r)
           ULONG cluster = xdffp->xdff_f.setdpbcounts.cluster;
           if (ISFAT32(dpb))
           {
-            if ((dpb->dpb_xfsinfosec == 0xffff
-                 && (nfreeclst != 0 || cluster != 0))
-                || nfreeclst == 1 || nfreeclst > dpb->dpb_xsize
-                || cluster == 1 || cluster > dpb->dpb_xsize)
+            if ((dpb->dpb_xfsinfosec == 0xffff && (nfreeclst | cluster)) ||
+                (nfreeclst | cluster) == 1 ||
+                nfreeclst > dpb->dpb_xsize ||
+                cluster > dpb->dpb_xsize)
             {
               return DE_INVLDPARM;
             }
@@ -246,8 +246,9 @@ int int21_fat32(lregs *r)
           }
           else
           {
-            if ((unsigned)nfreeclst == 1 || (unsigned)nfreeclst > dpb->dpb_size ||
-                (unsigned)cluster == 1 || (unsigned)cluster > dpb->dpb_size)
+            if (((unsigned)nfreeclst | (unsigned)cluster) == 1 ||
+                (unsigned)nfreeclst > dpb->dpb_size ||
+                (unsigned)cluster > dpb->dpb_size)
             {
               return DE_INVLDPARM;
             }
@@ -257,32 +258,16 @@ int int21_fat32(lregs *r)
           break;
         }
         case 0x01:
-        {
-          ddt *pddt = getddt(r->DL);
-          fmemcpy(&pddt->ddt_bpb, xdffp->xdff_f.rebuilddpb.bpbp,
+          fmemcpy(&getddt(r->DL)->ddt_bpb, xdffp->xdff_f.rebuilddpb.bpbp,
                   sizeof(bpb));
-        }
-        case 0x02:
-        {
-        rebuild_dpb:
-            /* hazard: no error checking! */
-          flush_buffers(dpb->dpb_unit);
-          dpb->dpb_flags = M_CHANGED;
-          
-          if (media_check(dpb) < 0)
-            return DE_INVLDDRV;
-          break;
-        }
+
         case 0x03:
         {
-          struct buffer FAR *bp;
-          bpb FAR *bpbp;
           DWORD newmirroring =
             xdffp->xdff_f.setmirroring.newmirroring;
-      
-          if (newmirroring != -1
-              && (ISFAT32(dpb)
-                  && (newmirroring & ~(0xf | 0x80))))
+          if (newmirroring != -1 &&
+              (newmirroring & ~0x8f) &&
+              ISFAT32(dpb))
           {
             return DE_INVLDPARM;
           }
@@ -290,39 +275,42 @@ int int21_fat32(lregs *r)
             (ISFAT32(dpb) ? dpb->dpb_xflags : 0);
           if (newmirroring != -1 && ISFAT32(dpb))
           {
-            bp = getblock(1, dpb->dpb_unit);
+            struct buffer FAR *bp = getblock(1, dpb->dpb_unit);
             bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT);
             bp->b_flag |= BFR_VALID | BFR_DIRTY;
-            bpbp = (bpb FAR *) & bp->b_buffer[BT_BPB];
-            bpbp->bpb_xflags = (UWORD)newmirroring;
+            ((bpb FAR*)(bp->b_buffer + BT_BPB))->bpb_xflags = (UWORD)newmirroring;
           }
           goto rebuild_dpb;
         }
         case 0x04:
         {
-          struct buffer FAR *bp;
-          bpb FAR *bpbp;
           DWORD rootclst = xdffp->xdff_f.setroot.newrootclst;
-          if (!ISFAT32(dpb)
-              || (rootclst != -1
-                  && (rootclst == 1
-                      || (ULONG)rootclst > dpb->dpb_xsize)))
+          if (!ISFAT32(dpb) ||
+              rootclst == 1 ||
+              rootclst != -1 && (ULONG)rootclst > dpb->dpb_xsize)
           {
             return DE_INVLDPARM;
           }
           xdffp->xdff_f.setroot.oldrootclst = dpb->dpb_xrootclst;
           if (rootclst != -1)
           {
-            bp = getblock(1, dpb->dpb_unit);
+            struct buffer FAR *bp = getblock(1, dpb->dpb_unit);
             bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT);
             bp->b_flag |= BFR_VALID | BFR_DIRTY;
-            bpbp = (bpb FAR *) & bp->b_buffer[BT_BPB];
-            bpbp->bpb_xrootclst = rootclst;
+            ((bpb FAR*)(bp->b_buffer + BT_BPB))->bpb_xrootclst = rootclst;
           }
-          goto rebuild_dpb;
+          /*goto rebuild_dpb;*/
         }
+        case 0x02:
+        rebuild_dpb:
+            /* hazard: no error checking! */
+          flush_buffers(dpb->dpb_unit);
+          dpb->dpb_flags = M_CHANGED;
+          
+          if (media_check(dpb) < 0)
+            return DE_INVLDDRV;
+          break;
       }
-    
       break;
     }
     /* Extended absolute disk read/write */
@@ -659,10 +647,8 @@ dispatch:
 
       /* Parse File Name                                              */
     case 0x29:
-      {
-        lr.SI = FcbParseFname(&rc, MK_FP(lr.DS, lr.SI), FP_ES_DI);
-        lr.AL = rc;
-      }
+      lr.SI = FcbParseFname(&rc, MK_FP(lr.DS, lr.SI), FP_ES_DI);
+      lr.AL = rc;
       break;
 
       /* Get Date                                                     */
@@ -826,10 +812,7 @@ dispatch:
     case 0x38:
       {
         UWORD cntry = lr.AL;
-
-        if (cntry == 0)
-          cntry = (UWORD) - 1;
-        else if (cntry == 0xff)
+        if (cntry == 0xff)
           cntry = lr.BX;
 
         if (0xffff == lr.DX)
@@ -840,11 +823,13 @@ dispatch:
         }
         else
         {
+          if (cntry == 0)
+            cntry--;
           /* Get Country Information */
           if ((rc = DosGetCountryInformation(cntry, FP_DS_DX)) < 0)
             goto error_invalid;
           /* HACK FIXME */
-          if (cntry == (UWORD) - 1)
+          if (cntry == (UWORD)-1)
             cntry = 1;
           /* END OF HACK */
           lr.AX = lr.BX = cntry;
@@ -1276,9 +1261,9 @@ dispatch:
     case 0x5c:
       if ((rc = DosLockUnlock
            (lr.BX,
-            (((unsigned long)lr.CX) << 16) | (((unsigned long)lr.DX) ),
-            (((unsigned long)lr.SI) << 16) | (((unsigned long)lr.DI) ),
-            ((lr.AX & 0xff) != 0))) != 0)
+            ((unsigned long)lr.CX << 16) | lr.DX,
+            ((unsigned long)lr.SI << 16) | lr.DI,
+            lr.AL != 0)) != 0)
         goto error_exit;
       break;
 /* /// End of additions for SHARE.  - Ron Cemer */
@@ -1759,13 +1744,14 @@ STATIC VOID StartTrace(VOID)
 }
 #endif
 
-/* this function is called from an assembler wrapper function
-   and serves the internal dos calls - int2f/12xx and int2f/4a01,4a02.
+/* this function is called from an assembler wrapper function and
+   serves the internal dos calls - int2f/12xx and int2f/4a01,4a02
 */
+
 struct int2f12regs {
 #ifdef I386
 #ifdef __WATCOMC__
-  /* UWORD gs, fs;  ** GS/FS are protected through SI/DI */
+  /* UWORD gs, fs; ** GS/FS are protected through SI/DI */
 #else
   UWORD high_edx, high_ecx, high_ebx, high_eax;
 #endif
@@ -1782,28 +1768,26 @@ struct int2f12regs {
  */
 VOID ASMCFUNC int2F_12_handler(struct int2f12regs r)
 {
-  if (r.AH == 0x4a)
+  if (r.AH == 0x4A)                    /* AX==0x4A01 or 0x4A02 */
   {
-    size_t size = 0, offs = 0xffff;
+    size_t size = ~(r.DI = HMAuserarea);/* remained HMA space; */
+                                       /*  offset 0xFFFF -> 0  */
+    r.ES = /*HMASEG*/0xFFFF;
 
-    r.ES = offs;
-    if (FP_SEG(firstAvailableBuf) == offs) /* HMA present? */
+    if (size && r.AL == 2)             /* allocate HMA space?  */
     {
-      offs = FP_OFF(firstAvailableBuf);
-      size = ~offs;                        /* BX for query HMA   */
-      if (r.AL == 0x02)                    /* allocate HMA space */
-      {
-        if (r.BX < size)
+      if (size > r.BX)
           size = r.BX;
-        AllocateHMASpace(offs, offs+size);
-        firstAvailableBuf += size;
-      }
+      freeHMAbuffers(HMAuserarea, HMAuserarea + size);
+      HMAuserarea += size;
     }
-    r.DI = offs;
+
     r.BX = size;
     return;
   }
 
+  /* INT 2F/12xx */
+
   switch (r.AL)
   {
     case 0x00:                 /* installation check */
@@ -1815,23 +1799,23 @@ VOID ASMCFUNC int2F_12_handler(struct in
       break;
 
     case 0x06:                 /* invoke critical error */
-
       /* code, drive number, error, device header */
-      r.AL = CriticalError(r.callerARG1 >> 8,
-                           (r.callerARG1 & (EFLG_CHAR << 8)) ? 0 :
-                           r.callerARG1 & 0xff, r.DI, MK_FP(r.BP, r.SI));
+      r.AL = CriticalError(hibyte (r.callerARG1),
+                           (r.callerARG1 & (EFLG_CHAR << 8))
+                               ? 0 : lobyte (r.callerARG1),
+                          r.DI, MK_FP(r.BP, r.SI));
       break;
 
     case 0x08:                 /* decrease SFT reference count */
-      {
-        sft FAR *p = MK_FP(r.ES, r.DI);
-
-        r.AX = p->sft_count;
-
-        if (--p->sft_count == 0)
-          --p->sft_count;
-      }
-      break;
+    {
+        sft FAR *p = FP_PTR (sft, r.ES, r.DI);
+        int cnt = p->sft_count;
+        r.AX = cnt;
+        if (--cnt == 0)
+          --cnt;
+        p->sft_count = cnt;
+        break;
+    }
 
     case 0x0c:                 /* perform "device open" for device, set owner for FCB 
*/
 
@@ -1851,25 +1835,23 @@ VOID ASMCFUNC int2F_12_handler(struct in
       break;
 
     case 0x0d:                 /* get dos date/time */
-
       r.AX = dos_getdate();
       r.DX = dos_gettime();
       break;
 
     case 0x11:                 /* normalise ASCIIZ filename */
     {
-      char c;
-      char FAR *s = MK_FP(r.DS, r.SI);
-      char FAR *t = MK_FP(r.ES, r.DI);
-
+      unsigned char c;
+      const char FAR *s = FP_PTR (const char, r.DS, r.SI);
+      char FAR *t = FP_PTR (char, r.ES, r.DI);
       do
       {
         c = *s++;
         /* uppercase character */
         /* for now, ASCII only because nls.c cannot handle DS!=SS */
-        if (c >= 'a' && c <= 'z')
-          c -= 'a' - 'A';
-        else if (c == '/')
+        if (c >= (UBYTE)'a' && c <= (UBYTE)'z')
+          c -= (UBYTE)('a' - 'A');
+        if (c == '/')
           c = '\\';
         *t++ = c;
       }
@@ -1878,39 +1860,38 @@ VOID ASMCFUNC int2F_12_handler(struct in
     }
 
     case 0x12:                 /* get length of asciiz string */
-
       r.CX = fstrlen(MK_FP(r.ES, r.DI)) + 1;
-
       break;
 
-    case 0x13:
-      /* uppercase character */  
+    case 0x13:         /* uppercase character */
+    {
       /* for now, ASCII only because nls.c cannot handle DS!=SS */
-      r.AL = (unsigned char)r.callerARG1;
-      if (r.AL >= 'a' && r.AL <= 'z')
-        r.AL -= 'a' - 'A';
+      unsigned char ch = lobyte (r.callerARG1);
+      if (ch >= (UBYTE)'a' && ch <= (UBYTE)'z')
+        ch -= (UBYTE)('a' - 'A');
+      r.AL = ch;
       break;
+    }
 
     case 0x16:
       /* get address of system file table entry - used by NET.EXE
-         BX system file table entry number ( such as returned from 2F/1220)
+         BX system file table entry number (such as returned from 2F/1220)
          returns
          ES:DI pointer to SFT entry
          BX relative entry number within SFT */
-      {
+    {
         int rel_idx = idx_to_sft_(r.BX);
-
         if (rel_idx == -1)
         {
           r.FLAGS |= FLG_CARRY;
           break;
         }
-        r.FLAGS &= ~FLG_CARRY;
         r.BX = rel_idx;
         r.ES = FP_SEG(lpCurSft);
         r.DI = FP_OFF(lpCurSft);
+        r.FLAGS &= ~FLG_CARRY;
         break;
-      }
+    }
 
     case 0x17:                 /* get current directory structure for drive - used by 
NET.EXE
                                    STACK: drive (0=A:,1=B,...)
@@ -1925,10 +1906,9 @@ VOID ASMCFUNC int2F_12_handler(struct in
                                    ;
                                    ; probable use: get sizeof(CDSentry)
                                  */
-      {
-        struct cds FAR *cdsp = get_cds(r.callerARG1 & 0xff);
-
-        if (cdsp == NULL)
+    {
+        const struct cds FAR *cdsp;
+        if ((cdsp = get_cds (lobyte (r.callerARG1))) == NULL)
         {
           r.FLAGS |= FLG_CARRY;
           break;
@@ -1937,7 +1917,7 @@ VOID ASMCFUNC int2F_12_handler(struct in
         r.SI = FP_OFF(cdsp);
         r.FLAGS &= ~FLG_CARRY;
         break;
-      }
+    }
 
     case 0x18:                 /* get caller's registers */
 
@@ -1945,28 +1925,24 @@ VOID ASMCFUNC int2F_12_handler(struct in
       r.SI = FP_OFF(user_r);
       break;
 
-    case 0x1b:                 /* #days in February - valid until 2099. */
-
-      r.AL = (r.CL & 3) ? 28 : 29;
+    case 0x1b:                 /* #days in February - valid until 2099 */
+      r.AL = (r.CL & (UBYTE)3u) ? 28 : 29;
       break;
 
     case 0x20:                 /* get job file table entry */
-      {
-        psp FAR *p = MK_FP(cu_psp, 0);
-        unsigned char FAR *idx;
-
+    {
+        const psp _seg *p = FP_SEG_PTR (const psp, cu_psp);
         if (r.BX >= p->ps_maxfiles)
         {
           r.AL = -DE_INVLDHNDL;
           r.FLAGS |= FLG_CARRY;
           break;
         }
-        idx = &p->ps_filetab[r.BX];
+        r.ES = FP_SEG (p->ps_filetab);
+        r.DI = FP_OFF (p->ps_filetab + r.BX);
         r.FLAGS &= ~FLG_CARRY;
-        r.ES = FP_SEG(idx);
-        r.DI = FP_OFF(idx);
-      }
-      break;
+        break;
+    }
 
     case 0x21:                 /* truename */
 
@@ -1975,23 +1951,19 @@ VOID ASMCFUNC int2F_12_handler(struct in
       break;
 
     case 0x23:                 /* check if character device */
-      {
-        struct dhdr FAR *dhp;
-
-        dhp = IsDevice((BYTE FAR *) DirEntBuffer.dir_name);
-
-        if (dhp == NULL)
+    {
+        const struct dhdr FAR *dhp;
+        if ((dhp = IsDevice (DirEntBuffer.dir_name)) == NULL)
         {
           r.FLAGS |= FLG_CARRY;
           break;
         }
         r.BH = dhp->dh_attr;
         r.FLAGS &= ~FLG_CARRY;
-      }
-      break;
+        break;
+    }
 
     case 0x25:                 /* get length of asciiz string */
-
       r.CX = fstrlen(MK_FP(r.DS, r.SI)) + 1;
       break;
 
@@ -2001,12 +1973,13 @@ VOID ASMCFUNC int2F_12_handler(struct in
       break;
 
     case 0x2c:                 /* added by James Tabor For Zip Drives
-                                   Return Null Device Pointer          */
-      /* by UDOS+RBIL: get header of SECOND device driver in device chain, 
-         omitting the NUL device TE */
+                                  Return Null Device Pointer
+                               */
+      /* by UDOS+RBIL: get header of SECOND device driver
+         in device chain, omitting the NUL device TE
+       */
       r.BX = FP_SEG(nul_dev.dh_next);
       r.AX = FP_OFF(nul_dev.dh_next);
-
       break;
 
     case 0x2e:                 /* GET or SET error table addresse - ignored
@@ -2017,17 +1990,10 @@ VOID ASMCFUNC int2F_12_handler(struct in
     default:
       if (r.AL <= 0x31)
       {
-        put_string("unimplemented internal dos function INT2F/12");
-        put_unsigned(r.AL, 16, 2);
+        put_string("unimplemented internal dos function INT2F/");
+        put_unsigned(r.AX, 16, 4);
         put_string("\n");
         r.FLAGS |= FLG_CARRY;
-        break;
       }
   }
 }
-
-/*
- * 2000/09/04  Brian Reifsnyder
- * Modified interrupts 0x25 & 0x26 to return more accurate error codes.
- */
-
diff -ruNp old/kernel/intr.asm new/kernel/intr.asm
--- old/kernel/intr.asm 2004-04-09 14:28:54.000000000 +0000
+++ new/kernel/intr.asm 2004-04-24 06:26:38.000000000 +0000
@@ -94,7 +94,9 @@
 
 segment        HMA_TEXT
 
-;; COUNT ASMPASCAL res_DosExec(COUNT mode, exec_blk * ep, BYTE * lp)
+;
+; int ASMPASCAL res_DosExec(int mode, exec_blk * ep, const char * lp);
+;
     global RES_DOSEXEC
 RES_DOSEXEC:
         pop es                  ; ret address
@@ -106,12 +108,13 @@ RES_DOSEXEC:
         push ds                 
         pop es                  ; es = ds
         int 21h
-        jc short no_exec_error
-        xor ax, ax
-no_exec_error:
+       sbb     dx,dx           ; CF=0?
+       and     ax,dx           ;  then ax=0
         ret
 
-;; UCOUNT ASMPASCAL res_read(int fd, void *buf, UCOUNT count); 
+;
+; unsigned ASMPASCAL res_read(int fd, void *buf, unsigned count);
+;
     global RES_READ
 RES_READ:
         pop ax         ; ret address
@@ -121,23 +124,20 @@ RES_READ:
         push ax        ; ret address
         mov ah, 3fh
         int 21h
-        jnc no_read_error
-        mov ax, -1
-no_read_error:
+       sbb     dx,dx           ; CF=1?
+       or      ax,dx           ;  then ax=-1
         ret
 
 segment        INIT_TEXT
 ;
-;       void init_call_intr(nr, rp)
-;       REG int nr
-;       REG struct REGPACK *rp
+; unsigned ASMPASCAL init_call_intr(int nr, iregs * rp);
 ;
                global  INIT_CALL_INTR
 INIT_CALL_INTR:
                INTR
 
 ;
-; int init_call_XMScall( (WORD FAR * driverAddress)(), WORD AX, WORD DX)
+; int ASMPASCAL init_call_XMScall(void FAR * driverAddress, UWORD ax, UWORD dx);
 ;
 ; this calls HIMEM.SYS 
 ;
@@ -154,8 +154,10 @@ INIT_CALL_XMSCALL:
             push es         ; driver address ("jmp es:cx")
             push cx
             retf
-            
-; void FAR *DetectXMSDriver(VOID)
+
+;
+; void FAR * ASMPASCAL DetectXMSDriver(VOID);            
+;
 global DETECTXMSDRIVER
 DETECTXMSDRIVER:
         mov ax, 4300h
@@ -163,8 +165,8 @@ DETECTXMSDRIVER:
 
         cmp al, 80h
         je detected
-        xor ax, ax
-        xor dx, dx
+        xor ax,ax
+       cwd
         ret
 
 detected:
@@ -179,13 +181,18 @@ detected:
         pop es
         ret        
 
+;
+; void ASMPASCAL keycheck(void);
+;
 global KEYCHECK
 KEYCHECK:
         mov ah, 1
         int 16h
         ret                
 
-;; int open(const char *pathname, int flags); 
+;
+; int ASMPASCAL open(const char *pathname, int flags); 
+;
     global INIT_DOSOPEN
 INIT_DOSOPEN: 
         ;; init calling DOS through ints:
@@ -198,13 +205,14 @@ INIT_DOSOPEN: 
 
 common_int21:
         int 21h
-        jnc common_no_error
-common_error:
-        mov ax, -1
-common_no_error:
+        jnc common_ret
+       sbb     ax,ax
+common_ret:
         ret
 
-;; int close(int fd);
+;
+; int ASMPASCAL close(int fd);
+;
     global CLOSE
 CLOSE:         
         pop ax         ; ret address
@@ -213,7 +221,9 @@ CLOSE:         
         mov ah, 3eh
         jmp short common_int21
 
-;; UCOUNT read(int fd, void *buf, UCOUNT count); 
+;
+; unsigned ASMPASCAL read(int fd, void *buf, unsigned count);
+;
     global READ
 READ: 
         pop ax         ; ret address
@@ -224,7 +234,9 @@ READ: 
         mov ah, 3fh
         jmp short common_int21
 
-;; int dup2(int oldfd, int newfd); 
+;
+; int ASMPASCAL dup2(int oldfd, int newfd);
+;
     global DUP2
 DUP2:
         pop ax         ; ret address
@@ -234,7 +246,9 @@ DUP2:
         mov ah, 46h
         jmp short common_int21
         
-;; VOID init_PSPSet(seg psp_seg)
+;
+; void ASMPASCAL init_PSPSet(seg psp_seg);
+;
     global INIT_PSPSET
 INIT_PSPSET:
         pop ax         ; ret address
@@ -244,7 +258,9 @@ INIT_PSPSET:
         int 21h
         ret
 
-;; COUNT init_DosExec(COUNT mode, exec_blk * ep, BYTE * lp)
+;
+; int ASMPASCAL init_DosExec(int mode, exec_blk * ep, const char * lp);
+;
     global INIT_DOSEXEC
 INIT_DOSEXEC:
         pop es                  ; ret address
@@ -256,12 +272,13 @@ INIT_DOSEXEC:
         push ds                 
         pop es                  ; es = ds
         int 21h
-        jc short exec_no_error
-        xor ax, ax
-exec_no_error:
+       sbb     dx,dx           ; CF=0?
+       and     ax,dx           ;  then ax=0
         ret
 
-;; int init_setdrive(int drive)
+;
+; int ASMPASCAL init_setdrive(int drive);
+;
    global INIT_SETDRIVE
 INIT_SETDRIVE:
        mov ah, 0x0e
@@ -272,28 +289,31 @@ common_dl_int21:
         int 21h
         ret
 
-;; int init_switchar(int char)
+;
+; int ASMPASCAL init_switchar(int chr);
+;
    global INIT_SWITCHAR
 INIT_SWITCHAR:
        mov ax, 0x3701
        jmp short common_dl_int21
 
-;; int allocmem(UWORD size, seg *segp)
+;
+; seg ASMPASCAL allocmem(UWORD size);
+;
     global ALLOCMEM
 ALLOCMEM:
         pop ax           ; ret address
-        pop dx           ; segp
         pop bx           ; size
         push ax          ; ret address
         mov ah, 48h
         int 21h
-        jc short common_error
-        mov bx, dx       ; segp
-        mov [bx], ax
-        xor ax, ax
+       sbb     bx,bx           ; CF=1?
+       or      ax,bx           ;  then ax=-1
         ret
                         
-;; void set_DTA(void far *dta)        
+;
+; void ASMPASCAL set_DTA(void far *dta);
+;
     global SET_DTA
 SET_DTA:
         pop ax           ; ret address
diff -ruNp old/kernel/proto.h new/kernel/proto.h
--- old/kernel/proto.h  2004-04-17 15:59:46.000000000 +0000
+++ new/kernel/proto.h  2004-04-24 07:24:36.000000000 +0000
@@ -33,6 +33,21 @@ static BYTE *Proto_hRcsId =
 #endif
 #endif
 
+typedef UWORD ofs_t;
+typedef UWORD seg_t;
+
+#if __TURBOC__ > 0x202
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type _seg*) (seg))
+#else
+# define _seg FAR
+# define FP_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
+# define FP_SEG_PTR(type,seg) ((type FAR*) MK_FP (seg, 0))
+#endif
+
+#define lobyte(x) ((UBYTE)(x))
+#define hibyte(x) ((UWORD)(x) >> 8)
+
 /* blockio.c */
 struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite);
 #define getblock(blkno, dsk) getblk(blkno, dsk, FALSE);
@@ -46,7 +61,7 @@ BOOL DeleteBlockInBufferCache(ULONG blkn
 UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks,
               COUNT mode);
 /* *** End of change */
-void AllocateHMASpace (size_t lowbuffer, size_t highbuffer);
+void freeHMAbuffers (ofs_t startarea, ofs_t nextarea);
 
 /* break.c */
 unsigned char ctrl_break_pressed(void);
@@ -227,8 +242,8 @@ void FcbCloseAll(void);
 UBYTE FcbFindFirstNext(xfcb FAR * lpXfcb, BOOL First);
 
 /* intr.asm */
-COUNT ASMPASCAL res_DosExec(COUNT mode, exec_blk * ep, BYTE * lp);
-UCOUNT ASMPASCAL res_read(int fd, void *buf, UCOUNT count);
+int ASMPASCAL res_DosExec(int mode, exec_blk * ep, const char * lp);
+unsigned ASMPASCAL res_read(int fd, void *buf, unsigned count);
 #ifdef __WATCOMC__
 #pragma aux (pascal) res_DosExec modify exact [ax bx dx es]
 #pragma aux (pascal) res_read modify exact [ax bx cx dx]
@@ -238,9 +253,6 @@ UCOUNT ASMPASCAL res_read(int fd, void *
 COUNT DosDevIOctl(lregs * r);
 
 /* memmgr.c */
-seg far2para(VOID FAR * p);
-seg long2para(ULONG size);
-void FAR *add_far(void FAR * fp, unsigned off);
 VOID FAR *adjust_far(const void FAR * fp);
 COUNT DosMemAlloc(UWORD size, COUNT mode, seg * para, UWORD * asize);
 COUNT DosMemLargest(UWORD * size);
@@ -452,5 +464,4 @@ VOID ASMCFUNC exec_user(iregs FAR * irp,
         ASSERT_CONST( (BYTE FAR *)x->fcb_ext - (BYTE FAR *)x->fcbname == 8)
 */
 
-#define ASSERT_CONST(x) { typedef struct { char _xx[x ? 1 : -1]; } xx ; }
-
+#define ASSERT_CONST(x) { typedef struct { char _[(x) ? 1 : -1]; } _; }




-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
_______________________________________________
Freedos-kernel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freedos-kernel

--- End Message ---

Reply via email to