mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-02 21:30:29 +00:00
move upperlevel function to libblock, add floppy_device_t
This commit is contained in:
parent
23e3126aa6
commit
8a787307e9
@ -9,7 +9,7 @@ CPPFLAGS = -I$(TOP)/../libmacos -DARCH_M68K
|
|||||||
|
|
||||||
LIBRARY = libfloppy.a
|
LIBRARY = libfloppy.a
|
||||||
|
|
||||||
SOURCES = floppy_lseek.c floppy_read.c floppy_read_sector.c
|
SOURCES = floppy_read_sector.c floppy_close.c floppy_open.c
|
||||||
|
|
||||||
HEADERS = libfloppy.h
|
HEADERS = libfloppy.h
|
||||||
|
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libfloppy.h"
|
|
||||||
|
|
||||||
int floppy_lseek(floppy_FILE *file, off_t offset, int whence)
|
|
||||||
{
|
|
||||||
long new_offset;
|
|
||||||
|
|
||||||
switch(whence)
|
|
||||||
{
|
|
||||||
case SEEK_SET:
|
|
||||||
new_offset = offset;
|
|
||||||
break;
|
|
||||||
case SEEK_CUR:
|
|
||||||
new_offset = file->offset + offset;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_offset < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
file->offset = new_offset;
|
|
||||||
|
|
||||||
return new_offset;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "libfloppy.h"
|
|
||||||
|
|
||||||
size_t floppy_read(floppy_FILE *file, void *ptr, size_t size)
|
|
||||||
{
|
|
||||||
int read = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
while (size != 0)
|
|
||||||
{
|
|
||||||
int part;
|
|
||||||
int cylinder_nb = file->offset / CYLINDER_SIZE;
|
|
||||||
int cylinder_offset = file->offset % CYLINDER_SIZE;
|
|
||||||
|
|
||||||
if (cylinder_nb != file->current_cylinder)
|
|
||||||
{
|
|
||||||
ret = floppy_read_sector((cylinder_nb * CYLINDER_SIZE) >> SECTOR_SIZE_BITS,
|
|
||||||
file->cylinder,
|
|
||||||
CYLINDER_SIZE);
|
|
||||||
if (ret == -1)
|
|
||||||
return read;
|
|
||||||
file->current_cylinder = cylinder_nb;
|
|
||||||
}
|
|
||||||
|
|
||||||
part = CYLINDER_SIZE - cylinder_offset;
|
|
||||||
if (part > size)
|
|
||||||
part = size;
|
|
||||||
memcpy(ptr, file->cylinder + cylinder_offset, part);
|
|
||||||
|
|
||||||
size -= part;
|
|
||||||
ptr = (char*)ptr + part;
|
|
||||||
file->offset += part;
|
|
||||||
read += part;
|
|
||||||
}
|
|
||||||
|
|
||||||
return read;
|
|
||||||
}
|
|
@ -15,7 +15,8 @@
|
|||||||
* size is the number of bytes to read
|
* size is the number of bytes to read
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int floppy_read_sector(off_t offset, void* buffer, size_t size)
|
int floppy_read_sector(floppy_device_t *device,
|
||||||
|
off_t offset, void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
ParamBlockRec_t param_block;
|
ParamBlockRec_t param_block;
|
||||||
@ -28,7 +29,7 @@ int floppy_read_sector(off_t offset, void* buffer, size_t size)
|
|||||||
memset(¶m_block, 0, sizeof(param_block));
|
memset(¶m_block, 0, sizeof(param_block));
|
||||||
|
|
||||||
param_block.ioBuffer = (unsigned long)buffer;
|
param_block.ioBuffer = (unsigned long)buffer;
|
||||||
param_block.ioVRefNum = 1;
|
param_block.ioVRefNum = device->unit + 1;
|
||||||
param_block.ioRefNum = -5;
|
param_block.ioRefNum = -5;
|
||||||
param_block.ioReqCount = size;
|
param_block.ioReqCount = size;
|
||||||
param_block.ioPosMode = fsFromStart;
|
param_block.ioPosMode = fsFromStart;
|
||||||
|
@ -11,14 +11,11 @@
|
|||||||
#define SECTOR_SIZE (1 << (SECTOR_SIZE_BITS))
|
#define SECTOR_SIZE (1 << (SECTOR_SIZE_BITS))
|
||||||
#define SECTOR_PER_TRACK 18
|
#define SECTOR_PER_TRACK 18
|
||||||
#define SIDE_NB 2
|
#define SIDE_NB 2
|
||||||
#define CYLINDER_SIZE (SIDE_NB*SECTOR_PER_TRACK*SECTOR_SIZE)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int offset;
|
int unit;
|
||||||
int current_cylinder;
|
} floppy_device_t;
|
||||||
unsigned char cylinder[CYLINDER_SIZE];
|
|
||||||
} floppy_FILE;
|
|
||||||
|
|
||||||
extern int floppy_read_sector(off_t offset, void* buffer, size_t size);
|
extern floppy_device_t *floppy_open(int unit);
|
||||||
extern size_t floppy_read(floppy_FILE *file, void *ptr, size_t size);
|
extern int floppy_close(floppy_device_t* device);
|
||||||
extern int floppy_lseek(floppy_FILE *file, off_t offset, int whence);
|
extern int floppy_read_sector(floppy_device_t *device,off_t offset, void* buffer, size_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user