home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / adhes / gstobject / squash / Example / Example (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1994-09-16  |  4.2 KB  |  92 lines

  1.  -- Example program to use messages object from BASIC
  2.  -- By George Taylor, george@tardis.ed.ac.uk
  3. $;" at line ";
  4.  "Adhesive"
  5.  "BasicC"
  6.  "UsefulBits"
  7.  "Squash"
  8.  -- This assembles Adhesive stuff and sets up an exit handler
  9.  -- to deregister with Adhesive when your program exits.
  10.  -- Because of the way BASIC works this exit handler is not called
  11.  -- if you generate an error with error number 0.
  12. _AdhesivePreInit
  13.  -- Register with Adhesive with the name "test Squash object".
  14.  -- The name is not important, it is only used for informational
  15.  -- purposes by Adhesive.
  16. _AdhesiveInit("test Squash object")
  17.  -- Request the basicC object from Adhesive.
  18. _AdhesiveRequest(
  19. _AssembleRequests_basicC)
  20.  -- Request the message object from Adhesive.
  21.  -- Note we do not need to know that the message object
  22.  -- requires the string+ object, Adhesive takes care of that
  23.  -- for us.
  24. _AdhesiveRequest(
  25. _AssembleRequests_squash)
  26.  -- We need to change HIMEM to give the C system some private workspace
  27.  -- after our program.
  28.  -- Do not make this smaller than 16K otherwise an error will occur.
  29.  -- If you wish to allocate more space to the C system without the
  30.  -- C system increasing your wimpslot then make the 16K larger.
  31.  -- With 16K there is about 2K available for malloc() and C stack,
  32.  -- the wimpslot is increased if possible when this runs out.
  33.  -- NOTE:  HIMEM must not be changed inside a procedure.
  34. -1024*16
  35.  -- Initialise C system. Make this call once and only once during the
  36.  -- execution of a program.
  37.  -- NOTE:  DO NOT change HIMEM after intialising with the C system or
  38.  --        your program will crash.
  39. _BasicCInit
  40.  -- Create C_printf%,C_malloc%,C_free% variables.
  41. _UsefulBitsInit
  42.  -- END OF INTIALISATION
  43.  -- When doing C calls which require a pointer to a buffer
  44.  -- for a 32bit result we shall pass a pointer into this buffer.
  45.  -- Don't try and put more than 256 bytes in this buffer!
  46. Q CPtrBuffer% = 
  47. _Zmalloc(256)
  48.  -- The calls squash_GetSize and squash_Load will work for any
  49.  -- file type. If the file is actually a squash file then this
  50.  -- is transparent to us. To verify this we test the files 'test1'
  51.  -- (a text file) and 'test2' (a squashed text file).
  52.  -- Find out size and filetype of file. We need the size so we
  53.  -- can allocate a buffer to load the file into. You would typically
  54.  -- check the filetype is correct for the files purpose (e.g. you
  55.  -- would check that a sprite resources file has the correct Sprite
  56.  -- file type).
  57.  -- NB. Squash is very effective on sprite files both in terms of
  58.  -- speed and compressed size.
  59. _squash_GetSize("test1",size%,filetype%)
  60.  '"File 'test1', size=";size%;", filetype="~filetype%
  61.  -- Allocate buffer for uncompressed file.
  62. buffer%=
  63. _Zmalloc(size%)
  64.  -- Load file.
  65. _squash_Load("test1",buffer%)
  66.  -- Do something with the file. We shall output the first line as
  67.  -- a string.
  68.  $(buffer%)
  69.  -- Free off the buffer space now we have finished with the loaded file.
  70. _Free(buffer%)
  71.  -- We now repeat the same operations with the file "test2".
  72. _squash_GetSize("test2",size%,filetype%)
  73.  '"File 'test2', size=";size%;", filetype="~filetype%
  74. buffer%=
  75. _Zmalloc(size%)
  76. _squash_Load("test2",buffer%)
  77.  $(buffer%)
  78. _Free(buffer%)
  79.  -- The procedures/functions below are used to provide an
  80.  -- even simpler interface to the squash code.
  81. _squash_GetSize(filename$, 
  82.  size%, 
  83.  filetype%)
  84.  basicC_CCall,squash_GetSize%,size%,filename$,CPtrBuffer%
  85. filetype%=!CPtrBuffer%
  86.  size%=-1 
  87. _Error("failed to read squash file '"+filename$+"'")
  88. _squash_Load(filename$, buf%)
  89.  basicC_CCall,squash_Load%,ok%,filename$,buf%
  90.  ok%=0 
  91. _Error("failed to load squash file '"+filename$+"'")
  92.