home *** CD-ROM | disk | FTP | other *** search
- {TITLE: Report free memory size}
- Program Memory;
-
- {Written by David G. Holm. Bix ID dgh. This program is in the public domain.}
- {WriteHex written by Jim Keohane (from his Turbo Pascal program Zap).}
-
- Type
-
- Flag_F_Type = (Carry,X1,Parity,X3,AuxCarry,X5,Zero,Sign,
- Trap,InterruptEnable,Direction,Overflow,X12,X13,X14,X15);
-
- FlagType = record case integer of
- 1: (f: set of Flag_F_Type);
- 2: (i: integer);
- end;
-
- RegBank = Record Case Boolean Of
- True: (AX,BX,CX,DX,BP,SI,DI,DS,ES: Integer;
- Flags: FlagType;);
- False: (AL,AH,BL,BH,CL,CH,DL,DH: Byte;);
- END;
-
- Var
- Regs: RegBank;
- MemSize: Real;
-
- Procedure WriteHex(Val: Byte);
-
- Const Hex: Array[0..15] Of Char = '0123456789ABCDEF';
- Hexs: String[15]='123456789ABCDEF';
-
- Var Zz: Integer;
-
- Begin
- For Zz:=1 To 2 Do
- Begin
- Case Zz Of
- 0:Write(chr(val));
- 1:Write(Hex[val shr 4]);
- 2:Write(Hex[val and 15])
- End
- End;
- End;
-
- Procedure WriteHex4 (Val: Integer);
- Begin
- WriteHex (Hi(Val));
- WriteHex (Lo(Val));
- End;
-
- Procedure WriteMemoryError;
- Begin
- Case Regs.AX of
- 7: WriteLn ('Arena trashed.');
- 8: WriteLn ('Not enough memory.');
- 9: WriteLn ('Invalid block.');
- else
- End {case}
- End;
-
- Begin
- Write ('Memory: ');
- (*DEBUG START
- writeln ('Modify memory allocation block.');
- DEBUG STOP*)
- Regs.AH := $4A; {Modify Memory Allocation Block}
- Regs.BX := $1000; {Cut allocated memory down to 64 K-bytes}
- Regs.ES := Cseg; {Com file...}
- MsDos (Regs);
- (*DEBUG START
- writehex4(regs.ax);
- write(' ');
- writehex4(regs.bx);
- write(' ');
- writehex4(regs.flags.i);
- writeln;
- DEBUG STOP*)
- If Carry in Regs.Flags.F
- Then WriteMemoryError
- Else
- Begin
- (*DEBUG START
- writeln ('Allocate memory.');
- DEBUG STOP*)
- Regs.AH := $48; {Allocate memory}
- Regs.BX := -1; {Allocate more than could possibly be available}
- MsDos (Regs);
- (*DEBUG START
- writehex4(regs.ax);
- write(' ');
- writehex4(regs.bx);
- write(' ');
- writehex4(regs.flags.i);
- writeln;
- DEBUG STOP*)
- If (Carry in Regs.Flags.F)
- Then If Regs.Ax <> 8
- Then WriteMemoryError
- Else
- Begin
- MemSize := Regs.BX + $1000; {Add in memory size of program}
- MemSize := MemSize * 16;
- Writeln (MemSize:1:0, ' bytes free.');
- End
- Else Writeln ('Over 1 Megabyte free.')
- End;
- End.