MCPcopy Create free account
hub / github.com/BlitterStudio/amiberry / parsenrg

Function parsenrg

src/blkdev_cdimage.cpp:2072–2244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2070}
2071
2072static int parsenrg(struct cdunit *cdu, struct zfile *znrg, const TCHAR *img, const TCHAR *curdir, const TCHAR *ocurdir)
2073{
2074 uae_s64 size;
2075 uae_s64 offset;
2076 bool ner5 = false;
2077 uae_u8 buf[256] = { 0 };
2078 int tracknum = 0;
2079 uae_u32 lastlba = 0;
2080 bool gotsession = false;
2081
2082 if (curdir)
2083 my_setcurrentdir(ocurdir, NULL);
2084
2085 size = zfile_size(znrg);
2086 zfile_fseek(znrg, size - 12, SEEK_SET);
2087 zfile_fread(buf, 12, 1, znrg);
2088 if (!memcmp(buf, "NER5", 4)) {
2089 offset = get_quad_host(buf + 4);
2090 ner5 = true;
2091 } else if (!memcmp(buf + 4, "NERO", 4)) {
2092 offset = get_long_host(buf + 8);
2093 } else {
2094 return 0;
2095 }
2096 if (offset < 0 || offset >= size - 12)
2097 return 0;
2098 zfile_fseek(znrg, offset, SEEK_SET);
2099 for (;;) {
2100 memset(buf, 0, 8);
2101 if (zfile_fread(buf, 8, 1, znrg) != 1)
2102 return 0;
2103 offset = zfile_ftell(znrg);
2104 uae_s32 size = get_long_host(buf + 4);
2105 buf[4] = 0;
2106 offset += size;
2107 if (!gotsession && !memcmp(buf, "ETN2", 4)) {
2108 tracknum = 1;
2109 int blocksize = 32;
2110 while (size >= blocksize) {
2111 uae_s64 toffset;
2112 uae_u32 lba;
2113 uae_u32 type;
2114 cdtoc *t = &cdu->toc[tracknum - 1];
2115 if (zfile_fread(buf, blocksize, 1, znrg) != 1)
2116 return 0;
2117 toffset = get_quad_host(buf);
2118 lba = get_long_host(buf + 20);
2119 type = get_long_host(buf + 16);
2120 t->offset = toffset;
2121 t->address = lba;
2122 if (type == 7) {
2123 t->size = 2352;
2124 t->enctype = AUDENC_PCM;
2125 } else if (type == 0 || type == 3) {
2126 t->size = 2048;
2127 t->ctrl |= 4;
2128 }
2129 t->track = tracknum;

Callers 1

parse_imageFunction · 0.85

Calls 11

my_setcurrentdirFunction · 0.85
zfile_sizeFunction · 0.85
zfile_fseekFunction · 0.85
zfile_freadFunction · 0.85
get_quad_hostFunction · 0.85
get_long_hostFunction · 0.85
zfile_ftellFunction · 0.85
zfile_dupFunction · 0.85
zfile_getnameFunction · 0.85
frombcdFunction · 0.85
get_word_hostFunction · 0.85

Tested by

no test coverage detected