mirror of
https://github.com/st3fan/ewm.git
synced 2025-01-16 03:30:10 +00:00
Fixes #82 Support nib files
This commit is contained in:
parent
70aef81778
commit
9df5355e31
38
src/dsk.c
38
src/dsk.c
@ -429,9 +429,23 @@ struct ewm_dsk_t *ewm_dsk_create(struct cpu_t *cpu) {
|
||||
}
|
||||
|
||||
int ewm_dsk_set_disk_data(struct ewm_dsk_t *dsk, uint8_t index, bool readonly, void *data, size_t length, int type) {
|
||||
assert(type == EWM_DSK_TYPE_DO || type == EWM_DSK_TYPE_PO);
|
||||
assert(index < 2);
|
||||
assert(length == (EWM_DSK_TRACKS * EWM_DSK_SECTORS * EWM_DSK_SECTOR_SIZE));
|
||||
if (type == EWM_DSK_TYPE_UNKNOWN) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (index > 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type == EWM_DSK_TYPE_DO || type == EWM_DSK_TYPE_PO) {
|
||||
if (length != (EWM_DSK_TRACKS * EWM_DSK_SECTORS * 256)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (type == EWM_DSK_TYPE_NIB) {
|
||||
if (length != (EWM_DSK_TRACKS * EWM_DSK_NIBBLES_PER_TRACK)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
struct ewm_dsk_drive_t *drive = &dsk->drives[index];
|
||||
|
||||
@ -451,9 +465,17 @@ int ewm_dsk_set_disk_data(struct ewm_dsk_t *dsk, uint8_t index, bool readonly, v
|
||||
drive->readonly = readonly;
|
||||
drive->dirty = false;
|
||||
|
||||
if (type == EWM_DSK_TYPE_DO || type == EWM_DSK_TYPE_PO) {
|
||||
for (int t = 0; t < EWM_DSK_TRACKS; t++) {
|
||||
drive->tracks[t] = dsk_convert_track(dsk, drive, data, t, type);
|
||||
}
|
||||
} else if (type == EWM_DSK_TYPE_NIB) {
|
||||
for (int t = 0; t < EWM_DSK_TRACKS; t++) {
|
||||
drive->tracks[t].length = 6656;
|
||||
drive->tracks[t].data = malloc(6656);
|
||||
memcpy(drive->tracks[t].data, data + (t * 6656), 6656);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -465,6 +487,9 @@ static int ewm_dsk_type_from_path(char *path) {
|
||||
if (ewm_utl_endswith(path, ".po")) {
|
||||
return EWM_DSK_TYPE_PO;
|
||||
}
|
||||
if (ewm_utl_endswith(path, ".nib")) {
|
||||
return EWM_DSK_TYPE_NIB;
|
||||
}
|
||||
return EWM_DSK_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
@ -485,10 +510,17 @@ int ewm_dsk_set_disk_file(struct ewm_dsk_t *dsk, uint8_t drive, bool readonly, c
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type == EWM_DSK_TYPE_DO || type == EWM_DSK_TYPE_PO) {
|
||||
if (file_info.st_size != (EWM_DSK_TRACKS * EWM_DSK_SECTORS * 256)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
} else if (type == EWM_DSK_TYPE_NIB) {
|
||||
if (file_info.st_size != (EWM_DSK_TRACKS * EWM_DSK_NIBBLES_PER_TRACK)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
char *data = calloc(file_info.st_size, 1);
|
||||
if (read(fd, data, file_info.st_size) != file_info.st_size) {
|
||||
|
12
src/dsk.h
12
src/dsk.h
@ -29,12 +29,13 @@
|
||||
struct cpu_t;
|
||||
struct mem_t;
|
||||
|
||||
#define EWM_DSK_DRIVE1 0
|
||||
#define EWM_DSK_DRIVE2 1
|
||||
#define EWM_DSK_DRIVE1 (0)
|
||||
#define EWM_DSK_DRIVE2 (1)
|
||||
|
||||
#define EWM_DSK_TRACKS 35
|
||||
#define EWM_DSK_SECTORS 16
|
||||
#define EWM_DSK_SECTOR_SIZE 256
|
||||
#define EWM_DSK_TRACKS (35)
|
||||
#define EWM_DSK_SECTORS (16)
|
||||
#define EWM_DSK_SECTOR_SIZE (256)
|
||||
#define EWM_DSK_NIBBLES_PER_TRACK (6656)
|
||||
|
||||
struct ewm_dsk_track_t {
|
||||
int length;
|
||||
@ -65,6 +66,7 @@ struct ewm_dsk_t {
|
||||
#define EWM_DSK_TYPE_UNKNOWN (-1)
|
||||
#define EWM_DSK_TYPE_DO (0)
|
||||
#define EWM_DSK_TYPE_PO (1)
|
||||
#define EWM_DSK_TYPE_NIB (2)
|
||||
|
||||
struct ewm_dsk_t *ewm_dsk_create(struct cpu_t *cpu);
|
||||
int ewm_dsk_set_disk_data(struct ewm_dsk_t *dsk, uint8_t index, bool readonly, void *data, size_t length, int type);
|
||||
|
Loading…
x
Reference in New Issue
Block a user