Hi!

- fix for INT21/38 (AL=0 processed "as is" for DX=-1).
- INT21/5C: parameter `unlock' of DosLockUnlock now explicitly receives 1
  when lr.AL nonzero.
- code optimization; some cleanups using previously defined macros.

DGROUP reduced from 164A to 1648;
HMA_TEXT reduced from 0a63eh to 0a633h.

--- Begin Message ---
diff -ruNp old/kernel/inthndlr.c new/kernel/inthndlr.c
--- old/kernel/inthndlr.c       2004-05-10 01:23:44.000000000 +0000
+++ new/kernel/inthndlr.c       2004-05-10 04:07:56.000000000 +0000
@@ -247,10 +247,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 ((nfreeclst != 0 || cluster != 0) &&
+                (dpb->dpb_xfsinfosec == 0xffff ||
+                 nfreeclst == 1 || nfreeclst > dpb->dpb_xsize ||
+                 cluster   == 1 || cluster   > dpb->dpb_xsize))
             {
               return DE_INVLDPARM;
             }
@@ -260,8 +260,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;
             }
@@ -271,13 +272,11 @@ 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));
-        }
+          /*goto rebuild_dpb;*/
+
         case 0x02:
-        {
         rebuild_dpb:
             /* hazard: no error checking! */
           flush_buffers(dpb->dpb_unit);
@@ -286,17 +285,14 @@ int int21_fat32(lregs *r)
           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;
           }
@@ -304,39 +300,33 @@ 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;
         }
       }
-    
       break;
     }
     /* Extended absolute disk read/write */
@@ -671,10 +661,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                                                     */
@@ -832,10 +820,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)
@@ -846,11 +831,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;
@@ -1280,11 +1267,9 @@ dispatch:
 /* /// Added for SHARE.  - Ron Cemer */
       /* Lock/unlock file access */
     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)
+      if ((rc = DosLockUnlock(lr.BX, ((unsigned long)lr.CX << 16) | lr.DX,
+                                     ((unsigned long)lr.SI << 16) | lr.DI,
+                                     lr.AL ? 1 : 0)) != 0)
         goto error_exit;
       break;
 /* /// End of additions for SHARE.  - Ron Cemer */
@@ -1799,6 +1784,8 @@ VOID ASMCFUNC int2F_12_handler(struct in
     return;
   }
 
+  /* INT 2F/12xx */
+
   switch (r.AL)
   {
     case 0x00:                 /* installation check */
@@ -1810,23 +1797,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 
*/
 
@@ -1846,25 +1833,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;
       }
@@ -1873,39 +1858,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,...)
@@ -1920,10 +1904,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;
@@ -1932,7 +1915,7 @@ VOID ASMCFUNC int2F_12_handler(struct in
         r.SI = FP_OFF(cdsp);
         r.FLAGS &= ~FLG_CARRY;
         break;
-      }
+    }
 
     case 0x18:                 /* get caller's registers */
 
@@ -1940,28 +1923,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 */
 
@@ -1970,23 +1949,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;
 
@@ -1996,12 +1971,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
@@ -2012,17 +1988,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.
- */
-

--- End Message ---

Reply via email to