Home » Archimedes archive » Acorn User » AU 1996-Xmas.adf » Features » Arcade/!Popcorn/c/LoadResF

Arcade/!Popcorn/c/LoadResF

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1996-Xmas.adf » Features
Filename: Arcade/!Popcorn/c/LoadResF
Read OK:
File size: 03A5 bytes
Load address: 0000
Exec address: 0000
File contents
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "DeskLib:h.File"
#include "DeskLib:h.Str"

#include "Popcorn:h.Popcorn"

os_error ERROR_OPEN = {0, "Couldn't open resource file"};

os_error *Popcorn_LoadResourceFile(char *filename)
{
  FILE          *handle;
  char		temp_name[256];

  handle = fopen(filename, "rb");
  if (handle == NULL)
    return(&ERROR_OPEN);

  while (!feof(handle))
  {
    resource[resource_free] = malloc(sizeof(struct resource));

    fscanf(handle, "%s %s\n", &(resource[resource_free]->group), temp_name);
    resource[resource_free]->file = malloc(strlen(temp_name)+2);
    strcpycr(resource[resource_free]->file, temp_name);
    resource[resource_free]->addr = NULL;
    resource[resource_free]->size = File_Size(temp_name);

/*     printf("%08X %s\n", resource[resource_free]->group, resource[resource_free]->file); */

    resource_free++;
  }
  fclose(handle);
  return(NULL);
}
00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
00000010  68 3e 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |h>.#include <std|
00000020  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
00000030  3c 73 74 72 69 6e 67 2e  68 3e 0a 0a 23 69 6e 63  |<string.h>..#inc|
00000040  6c 75 64 65 20 22 44 65  73 6b 4c 69 62 3a 68 2e  |lude "DeskLib:h.|
00000050  46 69 6c 65 22 0a 23 69  6e 63 6c 75 64 65 20 22  |File".#include "|
00000060  44 65 73 6b 4c 69 62 3a  68 2e 53 74 72 22 0a 0a  |DeskLib:h.Str"..|
00000070  23 69 6e 63 6c 75 64 65  20 22 50 6f 70 63 6f 72  |#include "Popcor|
00000080  6e 3a 68 2e 50 6f 70 63  6f 72 6e 22 0a 0a 6f 73  |n:h.Popcorn"..os|
00000090  5f 65 72 72 6f 72 20 45  52 52 4f 52 5f 4f 50 45  |_error ERROR_OPE|
000000a0  4e 20 3d 20 7b 30 2c 20  22 43 6f 75 6c 64 6e 27  |N = {0, "Couldn'|
000000b0  74 20 6f 70 65 6e 20 72  65 73 6f 75 72 63 65 20  |t open resource |
000000c0  66 69 6c 65 22 7d 3b 0a  0a 6f 73 5f 65 72 72 6f  |file"};..os_erro|
000000d0  72 20 2a 50 6f 70 63 6f  72 6e 5f 4c 6f 61 64 52  |r *Popcorn_LoadR|
000000e0  65 73 6f 75 72 63 65 46  69 6c 65 28 63 68 61 72  |esourceFile(char|
000000f0  20 2a 66 69 6c 65 6e 61  6d 65 29 0a 7b 0a 20 20  | *filename).{.  |
00000100  46 49 4c 45 20 20 20 20  20 20 20 20 20 20 2a 68  |FILE          *h|
00000110  61 6e 64 6c 65 3b 0a 20  20 63 68 61 72 09 09 74  |andle;.  char..t|
00000120  65 6d 70 5f 6e 61 6d 65  5b 32 35 36 5d 3b 0a 0a  |emp_name[256];..|
00000130  20 20 68 61 6e 64 6c 65  20 3d 20 66 6f 70 65 6e  |  handle = fopen|
00000140  28 66 69 6c 65 6e 61 6d  65 2c 20 22 72 62 22 29  |(filename, "rb")|
00000150  3b 0a 20 20 69 66 20 28  68 61 6e 64 6c 65 20 3d  |;.  if (handle =|
00000160  3d 20 4e 55 4c 4c 29 0a  20 20 20 20 72 65 74 75  |= NULL).    retu|
00000170  72 6e 28 26 45 52 52 4f  52 5f 4f 50 45 4e 29 3b  |rn(&ERROR_OPEN);|
00000180  0a 0a 20 20 77 68 69 6c  65 20 28 21 66 65 6f 66  |..  while (!feof|
00000190  28 68 61 6e 64 6c 65 29  29 0a 20 20 7b 0a 20 20  |(handle)).  {.  |
000001a0  20 20 72 65 73 6f 75 72  63 65 5b 72 65 73 6f 75  |  resource[resou|
000001b0  72 63 65 5f 66 72 65 65  5d 20 3d 20 6d 61 6c 6c  |rce_free] = mall|
000001c0  6f 63 28 73 69 7a 65 6f  66 28 73 74 72 75 63 74  |oc(sizeof(struct|
000001d0  20 72 65 73 6f 75 72 63  65 29 29 3b 0a 0a 20 20  | resource));..  |
000001e0  20 20 66 73 63 61 6e 66  28 68 61 6e 64 6c 65 2c  |  fscanf(handle,|
000001f0  20 22 25 73 20 25 73 5c  6e 22 2c 20 26 28 72 65  | "%s %s\n", &(re|
00000200  73 6f 75 72 63 65 5b 72  65 73 6f 75 72 63 65 5f  |source[resource_|
00000210  66 72 65 65 5d 2d 3e 67  72 6f 75 70 29 2c 20 74  |free]->group), t|
00000220  65 6d 70 5f 6e 61 6d 65  29 3b 0a 20 20 20 20 72  |emp_name);.    r|
00000230  65 73 6f 75 72 63 65 5b  72 65 73 6f 75 72 63 65  |esource[resource|
00000240  5f 66 72 65 65 5d 2d 3e  66 69 6c 65 20 3d 20 6d  |_free]->file = m|
00000250  61 6c 6c 6f 63 28 73 74  72 6c 65 6e 28 74 65 6d  |alloc(strlen(tem|
00000260  70 5f 6e 61 6d 65 29 2b  32 29 3b 0a 20 20 20 20  |p_name)+2);.    |
00000270  73 74 72 63 70 79 63 72  28 72 65 73 6f 75 72 63  |strcpycr(resourc|
00000280  65 5b 72 65 73 6f 75 72  63 65 5f 66 72 65 65 5d  |e[resource_free]|
00000290  2d 3e 66 69 6c 65 2c 20  74 65 6d 70 5f 6e 61 6d  |->file, temp_nam|
000002a0  65 29 3b 0a 20 20 20 20  72 65 73 6f 75 72 63 65  |e);.    resource|
000002b0  5b 72 65 73 6f 75 72 63  65 5f 66 72 65 65 5d 2d  |[resource_free]-|
000002c0  3e 61 64 64 72 20 3d 20  4e 55 4c 4c 3b 0a 20 20  |>addr = NULL;.  |
000002d0  20 20 72 65 73 6f 75 72  63 65 5b 72 65 73 6f 75  |  resource[resou|
000002e0  72 63 65 5f 66 72 65 65  5d 2d 3e 73 69 7a 65 20  |rce_free]->size |
000002f0  3d 20 46 69 6c 65 5f 53  69 7a 65 28 74 65 6d 70  |= File_Size(temp|
00000300  5f 6e 61 6d 65 29 3b 0a  0a 2f 2a 20 20 20 20 20  |_name);../*     |
00000310  70 72 69 6e 74 66 28 22  25 30 38 58 20 25 73 5c  |printf("%08X %s\|
00000320  6e 22 2c 20 72 65 73 6f  75 72 63 65 5b 72 65 73  |n", resource[res|
00000330  6f 75 72 63 65 5f 66 72  65 65 5d 2d 3e 67 72 6f  |ource_free]->gro|
00000340  75 70 2c 20 72 65 73 6f  75 72 63 65 5b 72 65 73  |up, resource[res|
00000350  6f 75 72 63 65 5f 66 72  65 65 5d 2d 3e 66 69 6c  |ource_free]->fil|
00000360  65 29 3b 20 2a 2f 0a 0a  20 20 20 20 72 65 73 6f  |e); */..    reso|
00000370  75 72 63 65 5f 66 72 65  65 2b 2b 3b 0a 20 20 7d  |urce_free++;.  }|
00000380  0a 20 20 66 63 6c 6f 73  65 28 68 61 6e 64 6c 65  |.  fclose(handle|
00000390  29 3b 0a 20 20 72 65 74  75 72 6e 28 4e 55 4c 4c  |);.  return(NULL|
000003a0  29 3b 0a 7d 0a                                    |);.}.|
000003a5