' PowerPacker support routine for AMOS 
' by Paul Huxham, March 1992 
'
' PowerPacker and powerpacker.library are © Nico Francois
' AMOS is © Mandarin Software
'
' Example code to read a PowerPackered file. 
' Please note that this routine will read any file, regardless 
' of whether it is packed or not. So it can be used for general  
' file loading.  
'
' 'powerpacker.library' is required to utilize this routine. 
' It can be obtained from FISH disk 623. 
'
'--------------------------------------------------------------------- 
'
' First load the file we require 
PPLOAD["s:startup-sequence"]
'
' Utilize the file loaded here 
' e.g. Display pages of 24 lines 
Screen Open 2,640,256,4,Hires
LINES=1
For I=BUFFER To BUFFER+BUFFER_LENGTH
   P=Peek(I)
   If P=10
      Print : Inc LINES
      If LINES=24
         Print "More......"
         Repeat : K$=Inkey$ : Until K$<>""
         LINES=1
      End If 
   Else 
      Print Chr$(P);
   End If 
Next I
'
' Now free the memory
MEMFREE[BUFFER,BUFFER_LENGTH]
Print : Print "End of File"
Repeat : K$=Inkey$ : Until K$<>""
Screen Close 2
End 
'
Procedure PPLOAD[FILENAME$]
   Shared BUFFER,BUFFER_LENGTH
   '
   ' First, ensure powerpacker.library is available 
   If Exist("libs:powerpacker.library")=False
      Print "powerpacker.library NOT available!"
      Stop 
   End If 
   '
   ' Now load the machine language
   If Exist("AMOSPPDecrunch.o")=True
      Erase 1
      Pload "AMOSPPDecrunch.o",1
   Else 
      Print "Decrunching code NOT found!"
      Stop 
   End If 
   '
   ' The filename is in FILENAME$ 
   '
   ' Check if the file exists or not  
   If Exist(FILENAME$)=False
      Print "File NOT found!"
      Stop 
   Else 
      ' Put the address of the string into Areg(0) 
      Areg(0)=Varptr(FILENAME$)
   End If 
   '
   ' Put the decrunch colour into Dreg(1) 
   Dreg(1)=0
   '
   ' Now call the assembler code
   Call(1)
   '
   ' Save the returned parameters 
   '
   BUFFER=Areg(1)
   BUFFER_LENGTH=Dreg(1)
   ERR=Dreg(0)
   '
   If ERR<>0
      Print "A Decrunching error occured!"
      Stop 
   End If 
End Proc
Procedure MEMFREE[BUFFER,BUFFER_LENGTH]
   '
   ' Free the memory allocated to us
   '
   Areg(1)=BUFFER
   Dreg(0)=BUFFER_LENGTH
   RESULT=Execall(-210)
End Proc
