Unit M_Curs;

interface

{$IFDEF DPMI}
 procedure LoadMouseCursor(CursorFile:string); export;
 procedure SaveMouseCursor(CursorFile:string); export;
{$ELSE}
 procedure LoadMouseCursor(CursorFile:string);
 procedure SaveMouseCursor(CursorFile:string);
{$ENDIF}

type CursorType   = array [0..15,0..15] of word ;

const MouseCursor:CursorType=
 ((  0,  0,256,256,256,256,256,256,256,256,256,256,256,256,256,256),
  (  0, 29,  0,256,256,256,256,256,256,256,256,256,256,256,256,256),
  (  0, 29, 27,  0,256,256,256,256,256,256,256,256,256,256,256,256),
  (  0, 29, 28, 26,  0,256,256,256,256,256,256,256,256,256,256,256),
  (  0, 29, 28, 26, 25,  0,256,256,256,256,256,256,256,256,256,256),
  (  0, 29, 28, 27, 25, 23,  0,256,256,256,256,256,256,256,256,256),
  (  0, 29, 28, 27, 25, 23, 22,  0,256,256,256,256,256,256,256,256),
  (  0, 29, 28, 27, 26, 23, 22, 21,  0,256,256,256,256,256,256,256),
  (  0, 29, 28, 27, 26, 23, 22, 21, 20,  0,256,256,256,256,256,256),
  (  0, 29, 28, 27, 26, 25, 22, 21, 20, 19,  0,256,256,256,256,256),
  (  0, 29, 28, 27, 26, 25, 22, 20, 19, 19, 19,  0,256,256,256,256),
  (  0, 29, 28, 26, 25, 23, 20, 20,  0,  0,  0,256,256,256,256,256),
  (  0, 29, 27, 25, 24, 22,  0,  0,256,256,256,256,256,256,256,256),
  (  0, 29, 26,  0,  0,  0,256,256,256,256,256,256,256,256,256,256),
  (  0,  0,  0,256,256,256,256,256,256,256,256,256,256,256,256,256),
  (256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256));

      MouseBack   : word = 256 ;
      MouseX      : byte = 0   ;
      MouseY      : byte = 0   ;

var  MousePos     : CursorType                  ;
     M_Result     : byte                        ;

implementation

type CUR_Header=record
                 FileID:array[0..3]of byte;        {vzdy "SCCF"}
                 HeaderSize:word;                  {vzdy 16 Bajtu}
                 Version:word;                     {verze: 11=1.1}
                 Fill:array[0..7]of byte;          {vypln do 16ti}
                 {nasleduje CUR_FileInfo}
                end;
     CUR_FileInfo=record
                   CursID:byte;                    {ozn. kurzoru (vzdy ".")}
                   NonDef_1:array[0..4]of byte;    {nedefinovano}
                   CursBits:word;                  {bitu na barvu}
                   CursBack:word;                  {barva pozadi}
                   CenterX:byte;                   {stred kurzoru (X)}
                   CenterY:byte;                   {stred kurzoru (Y)}
                   CursOfs:longint;                {ofset kurzoru}
                  end;

procedure LoadMouseCursor(CursorFile:string);
var F         : file         ;
    N         : word         ;
    Header    : CUR_Header   ;
    FileInfo  : CUR_FileInfo ;
    LC_Cursor : CursorType   ;
begin
 M_Result := 1;
 Assign(F,CursorFile);
 {$I-} Reset(F,1); {$I+}
 if IOResult<>0 then Exit;

 BlockRead(F, Header, SizeOf(CUR_Header));
 with Header do
  if (FileID[0] <> Ord('S')) and (FileID[1] <> Ord('C')) and
     (FileID[2] <> Ord('C')) and (FileID[3] <> Ord('F')) then
  begin
   Close(F);
   Exit;
  end;
 BlockRead(F, FileInfo, SizeOf(CUR_FileInfo));
 Seek(F, FileInfo.CursOfs);
 BlockRead(F, LC_Cursor, SizeOf(CursorType), N);
 if N=SizeOf(CursorType) then
 begin
  M_Result:=2;
  MouseCursor:=LC_Cursor;
  MouseBack := FileInfo.CursBack;
  MouseX := FileInfo.CenterX;
  MouseY := FileInfo.CenterY;
 end;
 Close(F);
end;

procedure SaveMouseCursor(CursorFile:string);
var F:file;
    N         : word       ;
    SC_ID     : word       ;
begin
 M_Result := 1;
 Assign(F,CursorFile);
 {$I-} ReWrite(F,1); {$I+}
 if IOResult<>0 then Exit;

 SC_ID := $4D43;
 BlockWrite(F,SC_ID,2,N);
 BlockWrite(F,MouseBack,2,N);
 BlockWrite(F,MouseCursor,SizeOf(CursorType),N);
 Close(F);
 M_Result:=2;
end;

begin
end.
