REM > JLibraries:Sprite.2

REM JB  19 Nov 1997     created


DEF PROCSprite_LoadFile(Path$, Fixd%, Name$)
LOCAL Buff%, Type%, Siz1%, Siz2%, Siz3%, Sqsh%, Work%

SYS"OS_File", 17, Path$ TO File%,, Type%,, Siz1%
IF File%  = 0 THEN ERROR 1, FNMess_Global1("NoFile", Path$)
IF File% <> 1 THEN ERROR 1, FNMess_Global1("IsntFil", Path$)
Type% = (Type% AND &FFF00) / &100

 CASE Type% OF
  WHEN &FF9
   Siz2% = Siz1%
  WHEN &FCA
   Sqsh% = FNHeap_Safe(Siz1%, 0, "_Sqsh")
   SYS"OS_File", 16, Path$, Sqsh%
   Siz2% = Sqsh%!04
  OTHERWISE
   ERROR 1, "'" + Path$ + "' is not a sprite file or squashed sprite file"
 ENDCASE

 IF Fixd% THEN
  DIM Buff% Siz2% + 8
  !Buff% = Buff% + 4
 ELSE
  Buff% = FNHeap_Alloc(Siz2% + 4)
  IF Buff% = 0 THEN ERROR Erro_Memo%, ""
 ENDIF
BuffB% = !Buff%
!BuffB% = Siz2% + 4

 CASE Type% OF
  WHEN &FF9
   SYS"OS_SpriteOp", 265, BuffB%
   SYS"OS_SpriteOp", 266, BuffB%, Path$
  WHEN &FCA
   SYS"Squash_Decompress", %1000, -1 TO Siz3%
   Work% = FNHeap_Safe(Siz3%, 0, "_Work")
   SYS"Squash_Decompress", %100, Work%, Sqsh% + 20, Siz1% - 20, BuffB% + 4, Siz2%
   PROCHeap_Lose(0, "_Sqsh")
   PROCHeap_Lose(0, "_Work")
 ENDCASE

PROCObject_Add(6, Buff%, 0, Name$)
SYS"WimpExt_Heap", 6
ENDPROC
