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(Bprint.exe$B$d(Bmouse.com$B$J$I$,$"$j$^$9!#(B

$B%W%m%0%i%_%s%0$N$?$a$N4pACCN<1(B

MCB

MS-DOS$B$O(BMCB (memory control block) $B$K$h$C$F%a%b%j!<$,4IM}$5$l$F$$$^$9!#(B MCB$B$O

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|+0|+1|+2|+3|+4|+5|+6|+7|+8|+9|+A|+B|+C|+D|+E|+F|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1|  2  |  3  |    4   |           5           |
+--+-----+-----+--------+-----------------------+

1: id (BYTE)       | 'M'$B$^$?$O(B'Z'
                   | ('M':$B(B(MS-DOS$B%P!<%8%g%s(B4$BL$K~$G$OL$;HMQ(B

$B$^$?!"(BMCB$B$O

+---+----+-----+--------+-----------------------+
|'M'|    |size0|        |                       | MCB 0
+---+----+-----+--------+-----------------------+
|$B%a%b%jNN0h(B0                                    | size0 [$B%Q%i%0%i%U(B]
+---+----+-----+--------+-----------------------+
|'M'|    |size1|        |                       | MCB 1
+---+----+-----+--------+-----------------------+
|$B%a%b%jNN0h(B1                                    | size1 [$B%Q%i%0%i%U(B]
+---+----+-----+--------+-----------------------+
|'M'|    |size2|        |                       |
+---+----+-----+--------+-----------------------+
                        :
                        :
+---+----+-----+--------+-----------------------+
|'Z'|    |sizeZ|        |                       | MCB Z
+---+----+-----+--------+-----------------------+
|$B%a%b%jNN0h(BZ                                    | sizeZ [$B%Q%i%0%i%U(B]
-------------------------------------------------

$B@hF,$N(BMCB$B%V%m%C%/$N%;%0%a%s%H(B ($B%*%U%;%C%H$O(B0000H) $B$r

$B$D$.$K(BMCB$B$r$?$I$k%W%m%0%i%`Nc$r<($7$^$9!#(B

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

typedef unsigned char BYTE;
typedef unsigned short int WORD;

int main(void)
{
    struct mcb {
        BYTE id;
        WORD owner;
        WORD size;
        BYTE reserve[3];
        char name[8];
    }
    far *pmcb;

    asm MOV AH, 52H;
    asm INT 21H;
    pmcb = MK_FP(*((WORD far *)MK_FP(_ES, _BX - 2)), 0x0000);

    for(;;) {
        printf("%04X owner = %04X, size = %X(%ld)\n",
               FP_SEG(pmcb), pmcb->owner,
               pmcb->size, (long)pmcb->size*16);

        if(pmcb->id == 'Z')
            break;
        else
            pmcb = MK_FP(FP_SEG(pmcb) + pmcb->size + 1, 0x0000);
    }

    return EXIT_SUCCESS;
}

PSP

PSP (program segment prefix)$B$O%W%m%0%i%`$,%m!<%I$5$l$k$H(B $B$=$N@hF,$K:n@.$5$l$k(B256$B%P%$%H$NNN0h$G!"

PSP$B$N9=B$(B
$B%*%U%;%C%H(B $B%5%$%:(B $BFbMF(B
00H WORD $B%W%m%0%i%`$N=*N;L?Na(B
02H WORD $B3d$jEv$F%a%b%j!<%V%m%C%/$ND>8e$N%;%0%a%s%H(B
04H BYTE $BM=Ls(B
05H BYTEx5 DOS$B5!G=$N(Bfar$B%3!<%k$N$?$a$N(B5$B%P%$%H(B
0AH DWORD INT 22H$B$N%3%T!<(B
0EH DWORD INT 23H$B$N%3%T!<(B
12H DWORD INT 24H$B$N%3%T!<(B
16H$B!A(B41H $BHs8x3+(B: $B$?$@$7(B2CH (DWORD): $B4D6-JQ?tNN0h$N%;%0%a%s%H$N$_8x3+(B
50H BYTEx3 INT 21H, RETF
53H BYTEx9 $BM=Ls(B
5CH BYTEx16 $BBh(B1FCB (file control block)
6CH BYTEx16 $BBh(B2FCB (file control block)
80H BYTE $B%3%^%s%I%i%$%s$NJ8;z?t(B
81H BYTEx127 $B%3%^%s%I%i%$%s(B (0DH$B$G%?!<%_%M%$%H(B)

80H$B0J9_$O%G%U%)%k%H$N(BDTA (disk transfer area)

C$B8@8l$N%a%b%j4IM}(B

C$B8@8l(B(BORLAND C++, small model)$B$G:n@.$5$l$?%W%m%0%i%`$O%m!<%ID>8e$O(B $B

-------------------------------------------------
|MCB                                            |
-------------------------------------------------  $B"+(B _psp:0x0000
|PSP                                            |
-------------------------------------------------  $B"+(B CS:0x0000
|_TEXT$B%/%i%9(B (CODE)                             |
-------------------------------------------------  $B"+(B DS:0x0000
|_DATA$B%/%i%9(B (DATA)                             |
-------------------------------------------------
|_BSS$B%/%i%9(B (BSS)                               |
-------------------------------------------------  $B"+(B DS:__heapbase
|near$B%R!<%W(B                                     |
------------------------$B"-(B-----------------------  $B"+(B DS:__brklvl
|<free>                                         |
------------------------$B",(B-----------------------  $B"+(B SS:SP
|$B%9%?%C%/(B                                       |
-------------------------------------------------
|far$B%R!<%W(B                                      |
-------------------------------------------------
|<free>                                         |
-------------------------------------------------
|                                               |
:                                               :
:                                               :

$BCm(B: $B%l%8%9%?(B (CS, DS, SS, SP) $B$r(BC$B8@8l$+$i%"%/%;%9$9$k$K$O(B _CS $B$N$h$&$K$7$F5<;wJQ?t$r;HMQ$7$^$9!#(B $BJQ?t$O(BC$B8@8l%l%Y%k$G5-=R$7$F$"$k$N$G(B $B%"%;%s%V%j8@8l$+$i%"%/%;%9$9$k$K$O@hF,$K(B _ $B$rIU2C$9$kI,MW$,$"$j$^$9!#(B

$BCm(B: __heapbase,__brklvl $B$OHs8x3+JQ?t$G$9!#(B[1]

near$B%R!<%W$O(Bmalloc$B$G

$B$?$@$7!"%R!<%W(B (near$B!&(Bfar$B$H$b(B)$B!&%9%?%C%/$O>oCs8e$K$OI,MW$NL5$$$b$N$G(B $B$9!#(B(malloc$B!&(Bfarmalloc$B$G%a%b%j$roCs%W%m%0%i(B $B%`$G$O$[$H$s$I;HMQ$7$J$$$H;W$$$^$9(B)

$B$7$?$,$C$F!"(Bnear$B%R!<%W$ND>A0$^$G$r>oCs$5$;$l$P$h$$$3$H$,$o$+$j$^$9!#(B $B$3$l$G$bI,MW$NL5$$ItJ,(B ($B=i4|2=ItJ,$J$I(B) $B$,>oCs$7$F$7$^$$$^$9$,!"(BC$B8@8l$G(B $B5-=R$9$k0J>e$O$3$l0J>e$OHs>o$KFq$7$/$J$j$^$9!#(B

$B%W%m%0%i%`(B

$B>oCs$9$k$@$1$N%W%m%0%i%`(B

$B>oCs$9$k$@$1$G2?$b$7$J$$%W%m%0%i%`$O

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

extern void _restorezero(void);

typedef unsigned char BYTE;
typedef unsigned short int WORD;

int main(void)
{
    WORD size;

    puts("$B>oCs%W%m%0%i%`%5%s%W%k(B");

    _restorezero();

    size = _SS - _psp + (_SP/16) + 20;  /* $B0lHV0BA4$J%5%$%:(B */

    asm MOV AH, 31H;
    asm MOV AL, 0;               /* EXIT_SUCCESS */
    asm MOV DX, size;
    asm INT 21H;

    return EXIT_SUCCESS;        /* dummy */
}

_restorezero $B4X?t$OHs8x3+$N%i%$%V%i%j4X?t$G3d9~%Y%/%?(B 00H, 04H, 05H, 06H$B$r85$KLa$7$^$9!#(B[1]

$B%a%$%s%a%b%j$N>pJs$rI=<($5$;$k$HoCs$7$?;v$,$o$+$j$^$9!#(B $B0J2<$O(Bms$B$K$h$k2hLLI=<($G$9!#(B

 MCB  PSP  Size      Owner name         Devices / Parameters(max 4
---- ---- ------- ----------------- ------------------------------
0587 0588   2624  melemm            (dv) EMMXXXX0
062C 0000     64  <free>
0631 0632     64  rpal98
0636 0682   1184  tsr_temp.exe(env) $B"+4D6-JQ?tNN0h(B
0681 0682  69488  tsr_temp.exe      $B"+%W%m%0%i%`K\BN(B
1779 17C4   1168  <free>
17C3 17C4 558000  <free>

$B$3$N%W%m%0%i%`$G$O%9%?%C%/$ND>A0$^$G>oCs$5$;$F$$$k$N$G(Bnear$B%R!<%W$r(B ($B>oCsIt$+$i(B) $B;HMQ$7$F$$$k>l9g$G$b@5>o$KF0:n$7$^$9!#(B $B$?$@$7!"Hs>o$K>oCs%5%$%:$,Bg$-$/$J$C$F$$$k$N$G

$B>oCs2r=|2DG=$J%W%m%0%i%`(B

$B>oCs$7$F$$$k$+$7$F$$$J$$$+$rH=CG$9$k$K$O!"%a%b%j$N$I$3$+$K(B $B!V>oCs$7$F$$$k!W$H$$$&L\0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$;$k$K$O(Btsr_is_stayed$B$^$?$O(Btsr_get_stayed_seg $B$G>oCs:Q$_$+$r3NG'$7!"(Btsr_stay$B$G>oCs!"(Btsr_remove$B$G3+J|$7$^$9!#(B $B4D6-JQ?tNN0h$O%W%m%0%i%^$N@UG$$G3+J|$7$J$1$l$P$J$j$^$;$s(B (dos_remove_env)$B!#(B

$B$^$?!"%^%/%mE83+$5$l$k$b$N$,$$$/$D$+$"$j$^$9$,!"(B $B4X?tL>$r(B "()"$B$G3g$k;v$K$h$jL@<(E*$K(B "$B4X?t(B" $B$r8F$S=P$9;v$,$G$-$^$9!#(B $B$3$l$O4X?tL>$N8e$N%[%o%$%H%9%Z!<%9(B ($B6uGr(B,TAB,$B2~9T(B) $B0J30$NJ8;z$,(B "(" $B0J30$G$"$k$H4X?t7?%^%/%m$NE83+$,9T$o$l$J$$$+$i$G$9!#(B

$BNc(B:

$B%W%m%0%i%`Nc$r0J2<$K<($7$^$9!#(B ($B4q?t2sL\$N5/F0$G>oCs$7!"6v?t2sL\$N5/F0$G3+J|$7$^$9(B)

#include <stdio.h>
#include <stdlib.h>
#include "dos.h"
#include "tsr.h"
#include "yasu.h"

#define IDOFS 0x0080                /* $B>oCs(Bid$B$N%*%U%;%C%H(B ($B?d>)CM(B) */
#define IDSTR "$$TSRSAMPLE$$"       /* $B>oCs(Bid */

extern WORD __heapbase;
extern WORD __brklvl;

int main(void)
{
    if(tsr_is_stayed(IDOFS, IDSTR)) /* $B>oCs$7$F$$$k$+(B? */
        tsr_remove(IDOFS, IDSTR);   /* $B$J$i$P3+J|(B */
    else {
        dos_remove_env();           /* $B4D6-JQ?tNN0h3+J|(B */
        tsr_stay(EXIT_SUCCESS, IDOFS, IDSTR,         /*$B>oCs(B */
                 _DS - _psp+(__heapbase/16 + 16));   /* $B"+Cm(B */
    }

    return EXIT_SUCCESS;
}

"$BCm(B" $B$NItJ,$O%3!<%I(B+$B%G!<%?NN0h$r>oCs$9$k$H$-$N?t;z$G$9!#(B $B>oCs$5$;$?$$NN0h$K$"$o$;$F

$BF0:n3NG'(B

$B0J2<$N4D6-$GF0:n$r3NG'$7$^$7$?!#(B

$BCx:n8"!&MxMQ>r7o(B

Copyright © 1994 HIRATA Yasuyuki, all rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

This software is provided by the author (HIRATA Yasuyuki) "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed.

In no event shall the author or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

$BCm0U(B: $B$3$N%i%$%;%s%9$O(BComputer fan$B$N5-;vCf$K=q$+$l$?%i%$%;%s%9$H$O0[$J$j$^$9!#(B Computer fan$B$K<}O?$5$l$F$$$k%U%!%$%k(B$B$O!"(B $B5-;vCf$N%i%$%;%s%9$H>e5-$N(BBSD$B%9%?%$%k$N%i%$%;%s%9$N(B $B$$$:$l$+0lJ}$N%i%$%;%s%9$rA*Br$9$k$3$H$,$G$-$^$9!#(B $B$?$@$7!"$3$3$+$iF~

$B%U%!%$%k(B

$B;29MJ88%(B


© 1994, 2001 HIRATA Yasuyuki <[email protected]>, all rights reserved.