mirror of
https://github.com/pevans/erc-c.git
synced 2024-11-23 23:32:45 +00:00
Add image type, image segment
This commit is contained in:
parent
c010c10ce2
commit
2dd21f1487
@ -16,6 +16,19 @@ typedef struct apple2dd apple2dd;
|
||||
#include "vm_bits.h"
|
||||
#include "vm_segment.h"
|
||||
|
||||
/*
|
||||
* Define the kind of image types that our disk media currently has. The
|
||||
* image type is something which is given to us when the disk is
|
||||
* "inserted", and it can't be changed during machine operation.
|
||||
* Well--it could--but we don't have a good reason to do so.
|
||||
*/
|
||||
enum apple2_dd_type {
|
||||
DD_NOTYPE,
|
||||
DD_DOS33,
|
||||
DD_PRODOS,
|
||||
DD_NIBBLE,
|
||||
};
|
||||
|
||||
/*
|
||||
* These are the possible modes a drive can be in.
|
||||
*/
|
||||
@ -116,10 +129,16 @@ struct apple2dd {
|
||||
int sector_pos;
|
||||
|
||||
/*
|
||||
* The data field is where the actual byte data for the image is
|
||||
* kept.
|
||||
* The data segment holds the literal data that the software running
|
||||
* in an Apple II would expect to see when accessing the device,
|
||||
* which is to say, data that is 6-and-2 encoded. The image segment
|
||||
* holds the data we literally read from a disk image file, which
|
||||
* (in most cases) is not 6-and-2 encoded. We also define an image
|
||||
* type (see apple2_dd_type for enums).
|
||||
*/
|
||||
vm_segment *data;
|
||||
vm_segment *image;
|
||||
int image_type;
|
||||
|
||||
/*
|
||||
* A disk drive may be "off" or "on", regardless of whether it's
|
||||
@ -160,7 +179,7 @@ struct apple2dd {
|
||||
extern SEGMENT_READER(apple2_dd_switch_read);
|
||||
extern SEGMENT_WRITER(apple2_dd_switch_write);
|
||||
extern apple2dd *apple2_dd_create();
|
||||
extern int apple2_dd_insert(apple2dd *, FILE *);
|
||||
extern int apple2_dd_insert(apple2dd *, FILE *, int);
|
||||
extern int apple2_dd_position(apple2dd *);
|
||||
extern vm_8bit apple2_dd_read(apple2dd *);
|
||||
extern void apple2_dd_eject(apple2dd *);
|
||||
|
@ -213,6 +213,8 @@ apple2_is_double_video(apple2 *mach)
|
||||
/*
|
||||
* Try to "boot" the apple2 machine. Look for input sources indicated in
|
||||
* the option system and load those into our disk drives.
|
||||
*
|
||||
* FIXME: we need to get the image type from the file name used
|
||||
*/
|
||||
int
|
||||
apple2_boot(apple2 *mach)
|
||||
@ -223,7 +225,7 @@ apple2_boot(apple2 *mach)
|
||||
// Do we have any disks?
|
||||
stream = option_get_input(1);
|
||||
if (stream) {
|
||||
err = apple2_dd_insert(mach->drive1, stream);
|
||||
err = apple2_dd_insert(mach->drive1, stream, DD_DOS33);
|
||||
if (err != OK) {
|
||||
log_critical("Unable to insert disk1 into drive");
|
||||
return err;
|
||||
@ -232,7 +234,7 @@ apple2_boot(apple2 *mach)
|
||||
|
||||
stream = option_get_input(2);
|
||||
if (stream) {
|
||||
err = apple2_dd_insert(mach->drive2, stream);
|
||||
err = apple2_dd_insert(mach->drive2, stream, DD_DOS33);
|
||||
if (err != OK) {
|
||||
log_critical("Unable to insert disk2 into drive");
|
||||
return err;
|
||||
|
@ -25,6 +25,7 @@ apple2_dd_create()
|
||||
// will depend on the disk you insert. For example, a DOS 3.3 or
|
||||
// ProDOS disk will have 140k, but a NIB file would have more.
|
||||
drive->data = NULL;
|
||||
drive->image = NULL;
|
||||
|
||||
drive->locked = false;
|
||||
drive->track_pos = 0;
|
||||
@ -34,6 +35,7 @@ apple2_dd_create()
|
||||
drive->mode = DD_READ;
|
||||
drive->phase_state = 0;
|
||||
drive->last_phase = 0;
|
||||
drive->image_type = DD_NOTYPE;
|
||||
|
||||
return drive;
|
||||
}
|
||||
@ -44,7 +46,7 @@ apple2_dd_create()
|
||||
* something we cannot accept.
|
||||
*/
|
||||
int
|
||||
apple2_dd_insert(apple2dd *drive, FILE *stream)
|
||||
apple2_dd_insert(apple2dd *drive, FILE *stream, int type)
|
||||
{
|
||||
struct stat finfo;
|
||||
int err;
|
||||
@ -79,6 +81,7 @@ apple2_dd_insert(apple2dd *drive, FILE *stream)
|
||||
return err;
|
||||
}
|
||||
|
||||
drive->image_type = type;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ TestSuite(apple2_dd, .init = setup, .fini = teardown);
|
||||
Test(apple2_dd, create)
|
||||
{
|
||||
cr_assert_eq(drive->data, NULL);
|
||||
cr_assert_eq(drive->image, NULL);
|
||||
cr_assert_eq(drive->image_type, DD_NOTYPE);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 0);
|
||||
cr_assert_eq(drive->online, false);
|
||||
@ -40,13 +42,14 @@ Test(apple2_dd, insert)
|
||||
drive->sector_pos = 33;
|
||||
|
||||
stream = fopen("../data/zero.img", "r");
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream), OK);
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream, DD_DOS33), OK);
|
||||
cr_assert_eq(drive->track_pos, 0);
|
||||
cr_assert_eq(drive->sector_pos, 0);
|
||||
cr_assert_eq(drive->image_type, DD_DOS33);
|
||||
fclose(stream);
|
||||
|
||||
stream = fopen("../data/bad.img", "r");
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream), ERR_BADFILE);
|
||||
cr_assert_eq(apple2_dd_insert(drive, stream, DD_DOS33), ERR_BADFILE);
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user