?? mcb.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 + -