Skip to content

Commit

Permalink
[adam][rom] read in chunks to avoid contention.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Oct 15, 2023
1 parent e873961 commit d2b2aef
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/media/adam/mediaTypeROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <cstring>

#include "../../include/debug.h"
#include "fnSystem.h"

#define ROM_BLOCK_SIZE 512

MediaTypeROM::MediaTypeROM()
{
Expand Down Expand Up @@ -56,6 +59,8 @@ bool MediaTypeROM::format(uint16_t *responsesize)

mediatype_t MediaTypeROM::mount(FILE *f, uint32_t disksize)
{
uint16_t o = 0;

Debug_print("ROM MOUNT\r\n");

_media_fileh = f;
Expand All @@ -65,10 +70,27 @@ mediatype_t MediaTypeROM::mount(FILE *f, uint32_t disksize)
disksize = 32768;

// Load ROM into memory.
if (fread(rom, 1, disksize, f) != disksize)
// Do this and yield in chonks so we don't starve the other threads

while (disksize)
{
_media_fileh = nullptr;
return MEDIATYPE_UNKNOWN;
uint16_t rsz = (disksize > ROM_BLOCK_SIZE ? ROM_BLOCK_SIZE : disksize);

Debug_printf("Reading %u bytes, %u bytes remaining\n",rsz,disksize);

if (fread(&rom[o], sizeof(uint8_t), rsz, f) != rsz)
{
fclose(f);
_media_fileh = nullptr;
return MEDIATYPE_UNKNOWN;
}
else
{
o += rsz;
disksize -= rsz;
}

fnSystem.yield(); // Let the system breathe.
}

return _mediatype;
Expand Down

0 comments on commit d2b2aef

Please sign in to comment.