Use hunksize from chd instead of header constant

This commit is contained in:
Zakk
2024-03-12 19:31:10 -04:00
parent 40501a8775
commit 3a0d20577e
7 changed files with 9 additions and 7 deletions

1
cd.h
View File

@@ -30,6 +30,7 @@ typedef struct
int last;
int sectorSize;
chd_file *chd_f;
int chd_hunksize;
cd_track_t tracks[100];
fileTYPE sub;

View File

@@ -301,7 +301,7 @@ static const char* load_chd_file(drive_t *drv, const char *chdfile)
free(drv->chd_hunkbuf);
}
drv->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK);
drv->chd_hunkbuf = (uint8_t *)malloc(tmpTOC.chd_hunksize);
drv->chd_hunknum = -1;
drv->chd_f = tmpTOC.chd_f;

View File

@@ -48,6 +48,7 @@ chd_error mister_load_chd(const char *filename, toc_t *cd_toc)
}
mister_chd_log("hunkbytes %d unitbytes %d logical length %llu\n", chd_header->hunkbytes, chd_header->unitbytes, chd_header->logicalbytes);
cd_toc->chd_hunksize = chd_header->hunkbytes;
//Set CLOEXEC on underlying FD
int chd_fd = fileno((FILE *)chd_core_file(cd_toc->chd_f)->argp);

View File

@@ -264,7 +264,7 @@ int cdd_t::Load(const char *filename)
free(this->chd_hunkbuf);
}
this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK);
this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize);
this->chd_hunknum = -1;
} else {
return (-1);

View File

@@ -264,7 +264,7 @@ int pcecdd_t::Load(const char *filename)
this->chd_hunkbuf = NULL;
}
this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK);
this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize);
this->chd_hunknum = -1;
} else {
return -1;

View File

@@ -16,7 +16,7 @@
#include <libchdr/chd.h>
static char buf[1024];
static uint8_t chd_hunkbuf[CD_FRAME_SIZE * CD_FRAMES_PER_HUNK];
static uint8_t *chd_hunkbuf = NULL;
static int chd_hunknum;
static int sgets(char *out, int sz, char **in)
@@ -108,7 +108,7 @@ static void unload_chd(toc_t *table)
{
chd_close(table->chd_f);
}
memset(chd_hunkbuf, 0, sizeof(chd_hunkbuf));
if (chd_hunkbuf) free(chd_hunkbuf);
memset(table, 0, sizeof(toc_t));
chd_hunknum = -1;
@@ -154,7 +154,7 @@ static int load_chd(const char *filename, toc_t *table)
table->end = table->tracks[table->last - 1].end + 1;
memset(chd_hunkbuf, 0, sizeof(chd_hunkbuf));
chd_hunkbuf = (uint8_t *)malloc(table->chd_hunksize);
chd_hunknum = -1;
return 1;

View File

@@ -339,7 +339,7 @@ int satcdd_t::Load(const char *filename)
free(this->chd_hunkbuf);
}
this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK);
this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize);
this->chd_hunknum = -1;
if (this->toc.tracks[0].sector_size)
{