Refactor disk interface API function names

This commit is contained in:
Aaron Culliney 2015-10-15 21:23:21 -07:00
parent 52d74aa43c
commit 4e478d369c
10 changed files with 90 additions and 77 deletions

View File

@ -260,8 +260,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject
LOG("...");
c_eject_6(0);
c_eject_6(1);
disk6_eject(0);
disk6_eject(1);
cpu_resume();
#endif
@ -312,10 +312,10 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, job
int ro = readOnly ? 1 : 0;
LOG(": (%s, %s, %s)", path, driveA ? "drive A" : "drive B", readOnly ? "read only" : "read/write");
if (c_new_diskette_6(drive, path, ro)) {
if (disk6_insert(drive, path, ro)) {
char *gzPath = NULL;
asprintf(&gzPath, "%s.gz", path);
if (c_new_diskette_6(drive, gzPath, ro)) {
if (disk6_insert(drive, gzPath, ro)) {
char *diskImageUnreadable = "Disk Image Unreadable";
unsigned int cols = strlen(diskImageUnreadable);
video_backend->animation_showMessage(diskImageUnreadable, cols, 1);
@ -331,7 +331,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, job
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEjectDisk(JNIEnv *env, jobject obj, jboolean driveA) {
LOG("...");
c_eject_6(!driveA);
disk6_eject(!driveA);
}
// ----------------------------------------------------------------------------

View File

@ -403,6 +403,7 @@ static void denibblize_track(int drive, uint8_t * const dst) {
offset = 0;
}
}
assert(sector >= 0 && sector < 16 && "invalid previous nibblization");
int sec_off = 256 * disk6.disk[drive].skew_table[ sector ];
denibblize_sector(work_buf, dst+sec_off);
sector = -1;
@ -669,10 +670,9 @@ GLUE_C_WRITE(disk_write_latch)
// ----------------------------------------------------------------------------
void disk_io_initialize(unsigned int slot) {
assert(slot == 6);
void disk6_init(void) {
/* load Disk II rom */
// load Disk II ROM
memcpy(apple_ii_64k[0] + 0xC600, slot6_rom, 0x100);
// disk softswitches
@ -694,9 +694,7 @@ void disk_io_initialize(unsigned int slot) {
}
cpu65_vmem_w[0xC0ED] = disk_write_latch;
}
void c_init_6(void) {
disk6.disk[0].phase = disk6.disk[1].phase = 0;
disk6.disk[0].track_valid = disk6.disk[1].track_valid = 0;
disk6.motor_time = (struct timespec){ 0 };
@ -705,7 +703,7 @@ void c_init_6(void) {
disk6.ddrw = 0;
}
const char *c_eject_6(int drive) {
const char *disk6_eject(int drive) {
const char *err = NULL;
@ -729,11 +727,11 @@ const char *c_eject_6(int drive) {
return err;
}
const char *c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
const char *disk6_insert(int drive, const char * const raw_file_name, int readonly) {
struct stat buf;
if (disk6.disk[drive].fp) {
c_eject_6(drive);
disk6_eject(drive);
}
/* uncompress the gziped disk */
@ -769,22 +767,22 @@ const char *c_new_diskette_6(int drive, const char * const raw_file_name, int fo
if (stat(disk6.disk[drive].file_name, &buf) < 0) {
disk6.disk[drive].fp = NULL;
c_eject_6(drive);
disk6_eject(drive);
return "disk unreadable 1";
} else {
if (!force) {
if (!readonly) {
disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r+");
disk6.disk[drive].is_protected = false;
}
if ((disk6.disk[drive].fp == NULL) || (force)) {
if ((disk6.disk[drive].fp == NULL) || readonly) {
disk6.disk[drive].fp = fopen(disk6.disk[drive].file_name, "r");
disk6.disk[drive].is_protected = true; /* disk is write protected! */
}
if (disk6.disk[drive].fp == NULL) {
/* Failed to open file. */
c_eject_6(drive);
disk6_eject(drive);
return "disk unreadable 2";
}
@ -801,25 +799,29 @@ const char *c_new_diskette_6(int drive, const char * const raw_file_name, int fo
return NULL;
}
void disk6_flush(int drive) {
// TODO ...
}
#if DISK_TRACING
void c_begin_disk_trace_6(const char *read_file, const char *write_file) {
if (read_file) {
test_read_fp = fopen(read_file, "w");
test_read_fp = TEMP_FAILURE_RETRY_FOPEN(fopen(read_file, "w"));
}
if (write_file) {
test_write_fp = fopen(write_file, "w");
test_write_fp = TEMP_FAILURE_RETRY_FOPEN(fopen(write_file, "w"));
}
}
void c_end_disk_trace_6(void) {
if (test_read_fp) {
fflush(test_read_fp);
fclose(test_read_fp);
TEMP_FAILURE_RETRY(fflush(test_read_fp));
TEMP_FAILURE_RETRY(fclose(test_read_fp));
test_read_fp = NULL;
}
if (test_write_fp) {
fflush(test_write_fp);
fclose(test_write_fp);
TEMP_FAILURE_RETRY(fflush(test_write_fp));
TEMP_FAILURE_RETRY(fclose(test_write_fp));
test_write_fp = NULL;
}
}

View File

@ -19,9 +19,10 @@
#include "common.h"
#define DSK_SIZE 143360
#define NIB_SIZE 232960
#define NI2_SIZE 223440
#define ERR_IMAGE_NOT_EXPECTED_SIZE "disk image is not expected size"
#define ERR_STAT_FAILED "disk image unreadable for stat"
#define ERR_CANNOT_OPEN "could not open disk image"
#define ERR_MMAP_FAILED "disk image unreadable for mmap"
#define NUM_TRACKS 35
#define NUM_SECTORS 16
@ -30,6 +31,10 @@
#define NIB_TRACK_SIZE 0x1A00 // NIB format
#define NI2_TRACK_SIZE 0x18F0 // NI2 format
#define DSK_SIZE (NUM_TRACKS * DSK_TRACK_SIZE) // 143360
#define NIB_SIZE (NUM_TRACKS * NIB_TRACK_SIZE) // 232960
#define NI2_SIZE (NUM_TRACKS * NI2_TRACK_SIZE) // 223440
#define PHASE_BYTES (NIB_TRACK_SIZE/2)
#define NIB_SEC_SIZE (NIB_TRACK_SIZE/NUM_SECTORS)
@ -74,10 +79,17 @@ typedef struct drive_t {
extern drive_t disk6;
void c_init_6(void);
const char *c_new_diskette_6(int drive, const char * const file_name, int force);
const char *c_eject_6(int drive);
void disk_io_initialize(unsigned int slot);
// initialize emulated 5.25 Disk ][ module
extern void disk6_init(void);
// insert 5.25 disk image file
extern const char *disk6_insert(int drive, const char * const file_name, int force);
// eject 5.25 disk image file
extern const char *disk6_eject(int drive);
// flush all I/O
extern void disk6_flush(int drive);
#if DISK_TRACING
void c_toggle_disk_trace_6(const char *read_file, const char *write_file);

View File

@ -344,7 +344,7 @@ static char zlibmenu[ZLIB_SUBMENU_H][ZLIB_SUBMENU_W+1] =
"||||||||||||||||||||||||||||||||||||||||" };
static void _eject_disk(int drive) {
const char *err_str = c_eject_6(drive);
const char *err_str = disk6_eject(drive);
if (err_str) {
int ch = -1;
snprintf(&zlibmenu[4][2], 37, "%s", err_str);
@ -588,7 +588,7 @@ void c_interface_select_diskette( int drive )
/* reopen disk, forcing write enabled */
if (toupper(ch) == 'W')
{
const char *err_str = c_new_diskette_6(drive, temp, 0);
const char *err_str = disk6_insert(drive, temp, /*readonly:*/0);
if (err_str)
{
int ch = -1;
@ -656,7 +656,7 @@ void c_interface_select_diskette( int drive )
_eject_disk(drive);
c_interface_print_screen( screen );
const char *err_str = c_new_diskette_6(drive, temp, (toupper(ch) != 'W'));
const char *err_str = disk6_insert(drive, temp, /*readonly:*/(toupper(ch) != 'W'));
if (err_str)
{
int ch = -1;
@ -1283,9 +1283,9 @@ void c_interface_parameters()
if (ch == 'Y')
{
save_settings();
c_eject_6( 0 );
disk6_eject(0);
c_interface_print_screen( screen );
c_eject_6( 1 );
disk6_eject(1);
c_interface_print_screen( screen );
#ifdef __linux__
LOG("Back to Linux, w00t!\n");

View File

@ -147,10 +147,10 @@ int test_setup_boot_disk(const char *fileName, int readonly) {
#else
asprintf(&disk, "%s/disks/%s", data_dir, fileName);
#endif
if (c_new_diskette_6(0, disk, readonly)) {
if (disk6_insert(0, disk, readonly)) {
int len = strlen(disk);
disk[len-3] = '\0'; // try again without '.gz' extension
err = (c_new_diskette_6(0, disk, readonly) != NULL);
err = (disk6_insert(0, disk, readonly) != NULL);
}
FREE(disk);
return err;

View File

@ -59,7 +59,7 @@ TEST test_boot_disk_bytes() {
BOOT_TO_DOS();
c_end_disk_trace_6();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -107,7 +107,7 @@ TEST test_boot_disk_bytes_nib() {
BOOT_TO_DOS();
c_end_disk_trace_6();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -160,7 +160,7 @@ TEST test_boot_disk_bytes_po() {
BOOT_TO_DOS();
c_end_disk_trace_6();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -265,7 +265,7 @@ TEST test_savehello_dsk() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -291,7 +291,7 @@ TEST test_savehello_nib() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -317,7 +317,7 @@ TEST test_savehello_po() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -388,7 +388,7 @@ TEST test_disk_bytes_savehello_dsk() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_DSK, 1);
@ -416,7 +416,7 @@ TEST test_disk_bytes_savehello_dsk() {
ASSERT(strcmp(mdstr0, EXPECTED_BSAVE_DSK_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -482,7 +482,7 @@ TEST test_disk_bytes_savehello_nib() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_NIB, 1);
@ -510,7 +510,7 @@ TEST test_disk_bytes_savehello_nib() {
ASSERT(strcmp(mdstr0, EXPECTED_BSAVE_NIB_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -581,7 +581,7 @@ TEST test_disk_bytes_savehello_po() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_PO, 1);
@ -609,7 +609,7 @@ TEST test_disk_bytes_savehello_po() {
ASSERT(strcmp(mdstr0, EXPECTED_BSAVE_PO_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -650,7 +650,7 @@ TEST test_outofspace_dsk() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_DSK, 1);
@ -678,7 +678,7 @@ TEST test_outofspace_dsk() {
ASSERT(strcmp(mdstr0, EXPECTED_OOS_DSK_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -705,7 +705,7 @@ TEST test_outofspace_nib() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_NIB, 1);
@ -733,7 +733,7 @@ TEST test_outofspace_nib() {
ASSERT(strcmp(mdstr0, EXPECTED_OOS_NIB_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -760,7 +760,7 @@ TEST test_outofspace_po() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
// Now verify actual disk bytes written to disk
test_setup_boot_disk(BLANK_PO, 1);
@ -788,7 +788,7 @@ TEST test_outofspace_po() {
ASSERT(strcmp(mdstr0, EXPECTED_OOS_PO_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -913,7 +913,7 @@ TEST test_bload_trace_dsk() {
unlink(disk);
FREE(disk);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1031,7 +1031,7 @@ TEST test_bload_trace_nib() {
unlink(disk);
FREE(disk);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1154,7 +1154,7 @@ TEST test_bload_trace_po() {
unlink(disk);
FREE(disk);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1181,7 +1181,7 @@ TEST test_inithello_dsk() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1206,7 +1206,7 @@ TEST test_inithello_nib() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1231,7 +1231,7 @@ TEST test_inithello_po() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
ASSERT_SHA(BOOT_SCREEN);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1266,7 +1266,7 @@ TEST test_data_stability_dsk() {
ASSERT(strcmp(mdstr0, EXPECTED_STABILITY_DSK_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1301,7 +1301,7 @@ TEST test_data_stability_nib() {
ASSERT(strcmp(mdstr0, EXPECTED_STABILITY_NIB_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1336,7 +1336,7 @@ TEST test_data_stability_po() {
ASSERT(strcmp(mdstr0, EXPECTED_STABILITY_PO_SHA) == 0);
} while(0);
c_eject_6(0);
disk6_eject(0);
PASS();
}
@ -1392,7 +1392,7 @@ GREATEST_SUITE(test_suite_disk) {
RUN_TESTp(test_data_stability_po);
// ...
c_eject_6(0);
disk6_eject(0);
pthread_mutex_unlock(&interface_mutex);
}

View File

@ -433,7 +433,7 @@ GREATEST_SUITE(test_suite_display) {
RUN_TEST(test_80col_hires);
// ...
c_eject_6(0);
disk6_eject(0);
pthread_mutex_unlock(&interface_mutex);
}

View File

@ -59,7 +59,7 @@ TEST test_boot_disk_cputrace() {
BOOT_TO_DOS();
cpu65_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -110,7 +110,7 @@ TEST test_cputrace_hello_dsk() {
c_debugger_go();
cpu65_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -160,7 +160,7 @@ TEST test_cputrace_hello_nib() {
c_debugger_go();
cpu65_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -210,7 +210,7 @@ TEST test_cputrace_hello_po() {
c_debugger_go();
cpu65_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -254,7 +254,7 @@ TEST test_boot_disk_vmtrace() {
BOOT_TO_DOS();
vm_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -302,7 +302,7 @@ TEST test_boot_disk_vmtrace_nib() {
BOOT_TO_DOS();
vm_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -350,7 +350,7 @@ TEST test_boot_disk_vmtrace_po() {
BOOT_TO_DOS();
vm_trace_end();
c_eject_6(0);
disk6_eject(0);
do {
uint8_t md[SHA_DIGEST_LENGTH];
@ -408,7 +408,7 @@ GREATEST_SUITE(test_suite_trace) {
#endif
// ...
c_eject_6(0);
disk6_eject(0);
pthread_mutex_unlock(&interface_mutex);
}

View File

@ -3452,7 +3452,7 @@ GREATEST_SUITE(test_suite_vm) {
RUN_TESTp(test_check_cxrom, /*CXROM*/1);
// ...
c_eject_6(0);
disk6_eject(0);
pthread_mutex_unlock(&interface_mutex);
}

View File

@ -1195,7 +1195,6 @@ static void _initialize_tables(void) {
#ifdef AUDIO_ENABLED
mb_io_initialize(4, 5); /* Mockingboard(s) and/or Phasor in slots 4 & 5 */
#endif
disk_io_initialize(6); /* Put a Disk ][ Controller in slot 6 */
}
// ----------------------------------------------------------------------------
@ -1205,7 +1204,7 @@ void vm_initialize(void) {
_initialize_apple_ii_memory();
_initialize_tables();
vm_reinitializeAudio();
c_init_6();
disk6_init();
_initialize_iie_switches();
c_joystick_reset();
}