mirror of
https://github.com/pevans/erc-c.git
synced 2024-10-08 23:55:39 +00:00
Rename apple2dd_ to apple2_dd_
Except for the struct object (apple2dd).
This commit is contained in:
parent
419b82faf1
commit
665f7de37c
@ -11,7 +11,7 @@
|
||||
/*
|
||||
* These are the possible modes a drive can be in.
|
||||
*/
|
||||
enum apple2dd_mode {
|
||||
enum apple2_dd_mode {
|
||||
DD_READ,
|
||||
DD_WRITE,
|
||||
};
|
||||
@ -101,17 +101,17 @@ typedef struct {
|
||||
bool write_protect;
|
||||
} apple2dd;
|
||||
|
||||
extern apple2dd *apple2dd_create();
|
||||
extern int apple2dd_insert(apple2dd *, FILE *);
|
||||
extern int apple2dd_position(apple2dd *);
|
||||
extern vm_8bit apple2dd_read(apple2dd *);
|
||||
extern void apple2dd_eject(apple2dd *);
|
||||
extern void apple2dd_free(apple2dd *);
|
||||
extern void apple2dd_set_mode(apple2dd *, int);
|
||||
extern void apple2dd_shift(apple2dd *, int);
|
||||
extern void apple2dd_step(apple2dd *, int);
|
||||
extern void apple2dd_turn_on(apple2dd *, bool);
|
||||
extern void apple2dd_write(apple2dd *, vm_8bit);
|
||||
extern void apple2dd_write_protect(apple2dd *, bool);
|
||||
extern apple2dd *apple2_dd_create();
|
||||
extern int apple2_dd_insert(apple2dd *, FILE *);
|
||||
extern int apple2_dd_position(apple2dd *);
|
||||
extern vm_8bit apple2_dd_read(apple2dd *);
|
||||
extern void apple2_dd_eject(apple2dd *);
|
||||
extern void apple2_dd_free(apple2dd *);
|
||||
extern void apple2_dd_set_mode(apple2dd *, int);
|
||||
extern void apple2_dd_shift(apple2dd *, int);
|
||||
extern void apple2_dd_step(apple2dd *, int);
|
||||
extern void apple2_dd_turn_on(apple2dd *, bool);
|
||||
extern void apple2_dd_write(apple2dd *, vm_8bit);
|
||||
extern void apple2_dd_write_protect(apple2dd *, bool);
|
||||
|
||||
#endif
|
||||
|
@ -10,7 +10,7 @@
|
||||
* the disk format.
|
||||
*/
|
||||
apple2dd *
|
||||
apple2dd_create()
|
||||
apple2_dd_create()
|
||||
{
|
||||
apple2dd *drive;
|
||||
|
||||
@ -40,7 +40,7 @@ apple2dd_create()
|
||||
* something we cannot accept.
|
||||
*/
|
||||
int
|
||||
apple2dd_insert(apple2dd *drive, FILE *stream)
|
||||
apple2_dd_insert(apple2dd *drive, FILE *stream)
|
||||
{
|
||||
struct stat finfo;
|
||||
int err;
|
||||
@ -62,7 +62,7 @@ apple2dd_insert(apple2dd *drive, FILE *stream)
|
||||
}
|
||||
|
||||
// If we have any data, get rid of it. We'll start fresh here.
|
||||
apple2dd_eject(drive);
|
||||
apple2_dd_eject(drive);
|
||||
|
||||
drive->data = vm_segment_create(finfo.st_size);
|
||||
drive->track_pos = 0;
|
||||
@ -83,7 +83,7 @@ apple2dd_insert(apple2dd *drive, FILE *stream)
|
||||
* upon track and sector position.
|
||||
*/
|
||||
int
|
||||
apple2dd_position(apple2dd *drive)
|
||||
apple2_dd_position(apple2dd *drive)
|
||||
{
|
||||
// Special case: they didn't load any image data into the "drive".
|
||||
// Return zero.
|
||||
@ -109,10 +109,10 @@ apple2dd_position(apple2dd *drive)
|
||||
* then shift the head by 1 byte.
|
||||
*/
|
||||
vm_8bit
|
||||
apple2dd_read(apple2dd *drive)
|
||||
apple2_dd_read(apple2dd *drive)
|
||||
{
|
||||
vm_8bit byte = vm_segment_get(drive->data, apple2dd_position(drive));
|
||||
apple2dd_shift(drive, 1);
|
||||
vm_8bit byte = vm_segment_get(drive->data, apple2_dd_position(drive));
|
||||
apple2_dd_shift(drive, 1);
|
||||
|
||||
return byte;
|
||||
}
|
||||
@ -122,7 +122,7 @@ apple2dd_read(apple2dd *drive)
|
||||
* memory and resetting the head position.
|
||||
*/
|
||||
void
|
||||
apple2dd_eject(apple2dd *drive)
|
||||
apple2_dd_eject(apple2dd *drive)
|
||||
{
|
||||
if (drive->data) {
|
||||
vm_segment_free(drive->data);
|
||||
@ -137,7 +137,7 @@ apple2dd_eject(apple2dd *drive)
|
||||
* Free the memory taken up by the disk drive.
|
||||
*/
|
||||
void
|
||||
apple2dd_free(apple2dd *drive)
|
||||
apple2_dd_free(apple2dd *drive)
|
||||
{
|
||||
if (drive->data) {
|
||||
vm_segment_free(drive->data);
|
||||
@ -151,7 +151,7 @@ apple2dd_free(apple2dd *drive)
|
||||
* be one or the other at a time.)
|
||||
*/
|
||||
void
|
||||
apple2dd_set_mode(apple2dd *drive, int mode)
|
||||
apple2_dd_set_mode(apple2dd *drive, int mode)
|
||||
{
|
||||
if (mode != DD_READ && mode != DD_WRITE) {
|
||||
return;
|
||||
@ -166,7 +166,7 @@ apple2dd_set_mode(apple2dd *drive, int mode)
|
||||
* moves further away from the center of the magnetic wafer.
|
||||
*/
|
||||
void
|
||||
apple2dd_shift(apple2dd *drive, int pos)
|
||||
apple2_dd_shift(apple2dd *drive, int pos)
|
||||
{
|
||||
drive->sector_pos += pos;
|
||||
|
||||
@ -176,7 +176,7 @@ apple2dd_shift(apple2dd *drive, int pos)
|
||||
|
||||
// We also need to move to the next track, so let's adjust by
|
||||
// two half-tracks.
|
||||
apple2dd_step(drive, 2);
|
||||
apple2_dd_step(drive, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ apple2dd_shift(apple2dd *drive, int pos)
|
||||
* against stepping too far out or too far in.
|
||||
*/
|
||||
void
|
||||
apple2dd_step(apple2dd *drive, int steps)
|
||||
apple2_dd_step(apple2dd *drive, int steps)
|
||||
{
|
||||
drive->track_pos += steps;
|
||||
|
||||
@ -203,7 +203,7 @@ apple2dd_step(apple2dd *drive, int steps)
|
||||
* A really simple function to turn the drive "on".
|
||||
*/
|
||||
void
|
||||
apple2dd_turn_on(apple2dd *drive, bool online)
|
||||
apple2_dd_turn_on(apple2dd *drive, bool online)
|
||||
{
|
||||
drive->online = online;
|
||||
}
|
||||
@ -214,10 +214,10 @@ apple2dd_turn_on(apple2dd *drive, bool online)
|
||||
* shift the drive position forward by one byte.
|
||||
*/
|
||||
void
|
||||
apple2dd_write(apple2dd *drive, vm_8bit byte)
|
||||
apple2_dd_write(apple2dd *drive, vm_8bit byte)
|
||||
{
|
||||
vm_segment_set(drive->data, apple2dd_position(drive), byte);
|
||||
apple2dd_shift(drive, 1);
|
||||
vm_segment_set(drive->data, apple2_dd_position(drive), byte);
|
||||
apple2_dd_shift(drive, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -227,7 +227,7 @@ apple2dd_write(apple2dd *drive, vm_8bit byte)
|
||||
* similar to just taping over or removing that tape.
|
||||
*/
|
||||
void
|
||||
apple2dd_write_protect(apple2dd *drive, bool protect)
|
||||
apple2_dd_write_protect(apple2dd *drive, bool protect)
|
||||
{
|
||||
drive->write_protect = protect;
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ static apple2dd *drive;
|
||||
static void
|
||||
setup()
|
||||
{
|
||||
drive = apple2dd_create();
|
||||
drive = apple2_dd_create();
|
||||
}
|
||||
|
||||
static void
|
||||
teardown()
|
||||
{
|
||||
apple2dd_free(drive);
|
||||
apple2_dd_free(drive);
|
||||
}
|
||||
|
||||
TestSuite(apple2dd, .init = setup, .fini = teardown);
|
||||
@ -38,13 +38,13 @@ Test(apple2dd, insert)
|
||||
drive->sector_pos = 33;
|
||||
|
||||
stream = fopen("../data/zero.img", "r");
|
||||
cr_assert_eq(apple2dd_insert(drive, stream), OK);
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream), OK);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 0);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("../data/bad.img", "r");
|
||||
cr_assert_eq(apple2dd_insert(drive, stream), ERR_BADFILE);
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream), ERR_BADFILE);
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ Test(apple2dd, position)
|
||||
// regardless of track position
|
||||
drive->track_pos = 3;
|
||||
drive->sector_pos = 44;
|
||||
cr_assert_eq(apple2dd_position(drive), 0);
|
||||
cr_assert_eq(apple2_dd_position(drive), 0);
|
||||
|
||||
// FIXME: we need some dummy data for the drive...
|
||||
}
|
||||
@ -65,11 +65,11 @@ Test(apple2dd, read)
|
||||
vm_segment_set(drive->data, 0, 123);
|
||||
vm_segment_set(drive->data, 1, 234);
|
||||
|
||||
cr_assert_eq(apple2dd_read(drive), 123);
|
||||
cr_assert_eq(apple2_dd_read(drive), 123);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 1);
|
||||
|
||||
cr_assert_eq(apple2dd_read(drive), 234);
|
||||
cr_assert_eq(apple2_dd_read(drive), 234);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 2);
|
||||
}
|
||||
@ -77,30 +77,30 @@ Test(apple2dd, read)
|
||||
Test(apple2dd, eject)
|
||||
{
|
||||
drive->data = vm_segment_create(1000);
|
||||
apple2dd_eject(drive);
|
||||
apple2_dd_eject(drive);
|
||||
cr_assert_eq(drive->data, NULL);
|
||||
}
|
||||
|
||||
Test(apple2dd, set_mode)
|
||||
{
|
||||
apple2dd_set_mode(drive, DD_WRITE);
|
||||
apple2_dd_set_mode(drive, DD_WRITE);
|
||||
cr_assert_eq(drive->mode, DD_WRITE);
|
||||
apple2dd_set_mode(drive, DD_READ);
|
||||
apple2_dd_set_mode(drive, DD_READ);
|
||||
cr_assert_eq(drive->mode, DD_READ);
|
||||
|
||||
// let's try shenanigans
|
||||
apple2dd_set_mode(drive, 111111111);
|
||||
apple2_dd_set_mode(drive, 111111111);
|
||||
cr_assert_eq(drive->mode, DD_READ);
|
||||
}
|
||||
|
||||
Test(apple2dd, shift)
|
||||
{
|
||||
apple2dd_shift(drive, 5);
|
||||
apple2_dd_shift(drive, 5);
|
||||
cr_assert_eq(drive->sector_pos, 5);
|
||||
|
||||
// Push it beyond the sector boundary; see if the track position
|
||||
// updates as it should.
|
||||
apple2dd_shift(drive, MAX_SECTOR_POS + 3);
|
||||
apple2_dd_shift(drive, MAX_SECTOR_POS + 3);
|
||||
cr_assert_eq(drive->track_pos, 2);
|
||||
|
||||
// this should be the mod of sector_pos and MAX_SECTOR_POS
|
||||
@ -110,32 +110,32 @@ Test(apple2dd, shift)
|
||||
Test(apple2dd, step)
|
||||
{
|
||||
// Does step work at all?
|
||||
apple2dd_step(drive, 5);
|
||||
apple2_dd_step(drive, 5);
|
||||
cr_assert_eq(drive->track_pos, 5);
|
||||
apple2dd_step(drive, 3);
|
||||
apple2_dd_step(drive, 3);
|
||||
cr_assert_eq(drive->track_pos, 8);
|
||||
apple2dd_step(drive, -2);
|
||||
apple2_dd_step(drive, -2);
|
||||
cr_assert_eq(drive->track_pos, 6);
|
||||
|
||||
// Do we handle going over the maximum track position properly?
|
||||
apple2dd_step(drive, 100);
|
||||
apple2_dd_step(drive, 100);
|
||||
cr_assert_eq(drive->track_pos, MAX_DRIVE_STEPS);
|
||||
|
||||
// Do we handle going to the 0 track properly if we get a radically
|
||||
// high number of negative track shifts?
|
||||
apple2dd_step(drive, -1000);
|
||||
apple2_dd_step(drive, -1000);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
}
|
||||
|
||||
Test(apple2dd, turn_on)
|
||||
{
|
||||
apple2dd_turn_on(drive, true);
|
||||
apple2_dd_turn_on(drive, true);
|
||||
cr_assert(drive->online);
|
||||
apple2dd_turn_on(drive, false);
|
||||
apple2_dd_turn_on(drive, false);
|
||||
cr_assert(!drive->online);
|
||||
|
||||
// I mean, ok
|
||||
apple2dd_turn_on(drive, 1111333);
|
||||
apple2_dd_turn_on(drive, 1111333);
|
||||
cr_assert(drive->online);
|
||||
}
|
||||
|
||||
@ -143,12 +143,12 @@ Test(apple2dd, write)
|
||||
{
|
||||
drive->data = vm_segment_create(_140K_);
|
||||
|
||||
apple2dd_write(drive, 123);
|
||||
apple2_dd_write(drive, 123);
|
||||
cr_assert_eq(vm_segment_get(drive->data, 0), 123);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 1);
|
||||
|
||||
apple2dd_write(drive, 234);
|
||||
apple2_dd_write(drive, 234);
|
||||
cr_assert_eq(vm_segment_get(drive->data, 1), 234);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 2);
|
||||
@ -156,10 +156,10 @@ Test(apple2dd, write)
|
||||
|
||||
Test(apple2dd, write_protect)
|
||||
{
|
||||
apple2dd_write_protect(drive, true);
|
||||
apple2_dd_write_protect(drive, true);
|
||||
cr_assert(drive->write_protect);
|
||||
apple2dd_write_protect(drive, false);
|
||||
apple2_dd_write_protect(drive, false);
|
||||
cr_assert(!drive->write_protect);
|
||||
apple2dd_write_protect(drive, 2222);
|
||||
apple2_dd_write_protect(drive, 2222);
|
||||
cr_assert(drive->write_protect);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user