⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mcb.c

📁 Embedded magazine source code. this is the source code in the year 1989
💻 C
字号:
static   MCB      *ma ;          /* Pointer to the current MCB */
static   MCB      *nma ;         /* Pointer to the next MCB */
static   MCB      *tmp ;         /* A working pointer to an MCB */
static   WORD     mcb ;          /* Application segment identifier */

/*
//    The basic scheme is to scan the allocation chain looking for the
//    specified block.  Once the block is found, shrink it (always possible)
//    or expand it as requested.
*/
      case DOS_REALLOC:
         /* Make a pointer to the MCB */
         ma = (MCB *) MK_FP(es - 1, 0) ;

         /* Verify we are pointing to an MCB */
         if (ma->id != 'M' && ma->id != 'Z')   {
            /* Bad block identifier - return an error code */
            ax = 9 ;
            psw |= 1 ;
            return ;
         }

         /* Now either shrink or expand it */
         if (bx > ma->size)   {
            /* Expand - is the next block is free/sufficiently large */
            nma = (MCB *) MK_FP(es + ma->size, 0) ;
            tmp = (MCB *) MK_FP(es + bx, 0) ;
            if (nma->owner != 0 || (ma->size + nma->size) < bx)   {
               /* Return the size block that can be allocated */
               ax = 8 ;
               bx = ma->size + ((nma->owner == 0) ? nma->size : 0) ;
               psw |= 1 ;
               return ;
            }

            /* Steal the space from the second MCB */
            mcb = bx - ma->size ;
            ma->size = bx ;

            /* Initialize the new smaller MCB */
            tmp->id = nma->id ;
            tmp->owner = nma->owner ;
            tmp->size = nma->size - mcb ;
         }
         else if (bx < ma->size)   {
            /* Release - create a new MCB holding the unallocated memory */
            tmp = (MCB *) MK_FP(es + ma->size, 0) ;
            nma = (MCB *) MK_FP(es + bx, 0) ;
            nma->size = ma->size - bx - 1 ;
            nma->owner = 0 ;
            nma->id = ma->id ;

            /* Shrink the size to the specified number */
            ma->size = bx ;

            /* Combine adjacent blocks if possible */
            if (ma->id != 'Z' && tmp->owner == 0)   {
               nma->size += tmp->size + 1 ;
               nma->id = tmp->id ;
            }

            /* Insert into the chain */
            if (ma->id == 'Z')
               ma->id = 'M' ;
         }
         break ;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -