PROGRAM SaveROM;
{ (C) by Stefan Haubenthal 1993/94 }
{ DISCLAIMER:  Usage of this image file is reserved for those users who
are already in posession of an Atari ST and thus having a legal right to
use the ROM software. This method is intended for those who lack the ability
to extract the image due to hardware shortcomings or system damage. }

USES    DOS;
CONST   Name='TOS.IMG';
        Len=$4000;
VAR     PtrROM,ROM:^LongInt;
        SP : Pointer;   { Used to save stack pointer. }
        Image:FILE;
        Max:INTEGER;
        Block:LongInt;
        Buffer:PACKED ARRAY [1..Len] OF Byte;

BEGIN
Sp := Super(NIL);     { Enter Supervisor mode. }
PtrROM:=Ptr($4f2);
ROM:=Ptr(PtrROM^);
WriteLn('Saving ',Name,' V',LoWord(Hi(ROM^)),'.',LoWord(Lo(ROM^)));
ReWrite(Image,Name);
Max:=$30000 DIV Len-1;
FOR Block:=0 TO Max DO
        BEGIN
        ROM:=Ptr(PtrROM^+Block*Len);
        IF Block<Max THEN Move(ROM^,Buffer,Len)
                     ELSE BEGIN
                          Move(ROM^,Buffer,Len-1);
                          Buffer[Len]:=$5c;
                          END;
        BlockWrite(Image,Buffer,Len);
        END;
END.
