EMILE/second/load.c

80 lines
1.5 KiB
C
Raw Normal View History

2004-05-26 21:59:06 +00:00
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
2004-07-12 21:32:44 +00:00
#include "bank.h"
#include "misc.h"
2004-05-26 21:59:06 +00:00
#include "glue.h"
2004-12-03 00:19:02 +00:00
#include "head.h"
2004-05-26 21:59:06 +00:00
#include "load.h"
2004-12-03 00:19:02 +00:00
#ifdef SCSI_SUPPORT
#include "scsi.h"
static int load_container(struct emile_container* container, char* image)
2004-05-26 21:59:06 +00:00
{
2004-12-03 00:19:02 +00:00
int target;
int i;
2004-05-26 21:59:06 +00:00
int err;
2004-12-03 00:19:02 +00:00
target = container->unit_id;
2004-05-26 21:59:06 +00:00
2004-12-03 00:19:02 +00:00
i = 0;
while (container->blocks[i].count != 0)
2004-05-26 21:59:06 +00:00
{
2004-12-03 00:19:02 +00:00
err = scsi_READ(target, container->blocks[i].offset,
container->blocks[i].count,
image,
container->block_size * container->blocks[i].count);
if (err != noErr)
return -1;
2004-12-03 00:19:02 +00:00
image += container->block_size * container->blocks[i].count;
i++;
2004-05-26 21:59:06 +00:00
}
return 0;
2004-12-03 00:19:02 +00:00
}
#else /* SCSI_SUPPORT */
static int load_blocks(unsigned long offset, unsigned long size, char *image)
2004-12-03 00:19:02 +00:00
{
int err;
ParamBlockRec_t param_block;
2004-06-07 18:51:51 +00:00
2004-05-26 21:59:06 +00:00
memset(&param_block, 0, sizeof(param_block));
param_block.ioBuffer = (unsigned long)image;
2004-12-03 00:19:02 +00:00
param_block.ioVRefNum = 1;
2004-05-26 21:59:06 +00:00
param_block.ioRefNum = -5;
param_block.ioReqCount = size;
param_block.ioPosMode = fsFromStart;
param_block.ioPosOffset = offset;
err = PBReadSync(&param_block);
if (err != noErr)
return -1;
2004-05-26 21:59:06 +00:00
return 0;
2004-05-26 21:59:06 +00:00
}
2004-12-03 00:19:02 +00:00
#endif /* SCSI_SUPPORT */
int load_image(unsigned long offset, unsigned long size, char *image)
2004-12-03 00:19:02 +00:00
{
if (size == 0)
return -1;
2004-12-03 00:19:02 +00:00
if (image == NULL)
return -1;
2004-12-03 00:19:02 +00:00
#ifdef SCSI_SUPPORT
return load_container((struct emile_container*)offset, image);
#else
return load_blocks(offset, size, image);
#endif
}