mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-06-24 11:29:33 +00:00
Refactor INTERFACE_CLASS stuff out of disk API
This commit is contained in:
parent
1b8387d214
commit
afc15e0b63
55
src/disk.c
55
src/disk.c
|
@ -115,44 +115,21 @@ void c_init_6()
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef INTERFACE_CLASSIC
|
||||
#define ZLIB_SUBMENU_H 7
|
||||
#define ZLIB_SUBMENU_W 40
|
||||
static char zlibmenu[ZLIB_SUBMENU_H][ZLIB_SUBMENU_W+1] =
|
||||
//1. 5. 10. 15. 20. 25. 30. 35. 40.
|
||||
{ "||||||||||||||||||||||||||||||||||||||||",
|
||||
"| |",
|
||||
"| An error occurred when attempting to |",
|
||||
"| handle a compressed disk image: |",
|
||||
"| |",
|
||||
"| |",
|
||||
"||||||||||||||||||||||||||||||||||||||||" };
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
c_eject_6() - ejects/gzips image file
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void c_eject_6(int drive) {
|
||||
const char *c_eject_6(int drive) {
|
||||
|
||||
const char *err = NULL;
|
||||
|
||||
if (disk6.disk[drive].compressed)
|
||||
{
|
||||
// foo.dsk -> foo.dsk.gz
|
||||
const char* const err = def(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
|
||||
if (err)
|
||||
{
|
||||
err = def(disk6.disk[drive].file_name, is_nib(disk6.disk[drive].file_name) ? NIB_SIZE : DSK_SIZE);
|
||||
if (err) {
|
||||
ERRLOG("OOPS: An error occurred when attempting to compress a disk image : %s", err);
|
||||
#ifdef INTERFACE_CLASSIC
|
||||
int ch = -1;
|
||||
snprintf(&zlibmenu[4][2], 37, "%s", err);
|
||||
c_interface_print_submenu_centered(zlibmenu[0], ZLIB_SUBMENU_W, ZLIB_SUBMENU_H);
|
||||
while ((ch = c_mygetch(1)) == -1) {
|
||||
// ...
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
unlink(disk6.disk[drive].file_name);
|
||||
}
|
||||
}
|
||||
|
@ -165,6 +142,8 @@ void c_eject_6(int drive) {
|
|||
fclose(disk6.disk[drive].fp);
|
||||
disk6.disk[drive].fp = NULL;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
|
@ -172,7 +151,7 @@ void c_eject_6(int drive) {
|
|||
inserts a new disk image into the appropriate drive.
|
||||
return 0 on success
|
||||
------------------------------------------------------------------------- */
|
||||
int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
||||
const char *c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
||||
struct stat buf;
|
||||
|
||||
/* uncompress the gziped disk */
|
||||
|
@ -190,16 +169,8 @@ int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
|||
if (err)
|
||||
{
|
||||
ERRLOG("OOPS: An error occurred when attempting to inflate/load a disk image : %s", err);
|
||||
#ifdef INTERFACE_CLASSIC
|
||||
int ch = -1;
|
||||
snprintf(&zlibmenu[4][2], 37, "%s", err);
|
||||
c_interface_print_submenu_centered(zlibmenu[0], ZLIB_SUBMENU_W, ZLIB_SUBMENU_H);
|
||||
while ((ch = c_mygetch(1)) == -1) {
|
||||
// ...
|
||||
}
|
||||
#endif
|
||||
free(file_name);
|
||||
return 1;
|
||||
return err;
|
||||
}
|
||||
if (unlink(file_name)) // temporarily remove .gz file
|
||||
{
|
||||
|
@ -226,7 +197,7 @@ int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
|||
{
|
||||
disk6.disk[drive].fp = NULL;
|
||||
c_eject_6(drive);
|
||||
return 1; /* problem: disk unreadable */
|
||||
return "disk unreadable 1";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -248,7 +219,7 @@ int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
|||
{
|
||||
/* Failed to open file. */
|
||||
c_eject_6(drive);
|
||||
return 1; /* problem: disk unreadable */
|
||||
return "disk unreadable 2";
|
||||
}
|
||||
|
||||
/* seek to current head position. */
|
||||
|
@ -258,7 +229,7 @@ int c_new_diskette_6(int drive, const char * const raw_file_name, int force) {
|
|||
disk6.disk[drive].sector = 0;
|
||||
disk6.disk[drive].run_byte = 0;
|
||||
|
||||
return 0; /* no problem */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ struct drive
|
|||
extern struct drive disk6;
|
||||
|
||||
void c_init_6();
|
||||
int c_new_diskette_6(int drive, const char * const file_name, int force);
|
||||
void c_eject_6(int drive);
|
||||
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);
|
||||
|
||||
void disk_read_nop(),
|
||||
|
|
|
@ -327,6 +327,29 @@ void c_interface_exit(int ch)
|
|||
/* -------------------------------------------------------------------------
|
||||
c_interface_select_diskette()
|
||||
------------------------------------------------------------------------- */
|
||||
#define ZLIB_SUBMENU_H 7
|
||||
#define ZLIB_SUBMENU_W 40
|
||||
static char zlibmenu[ZLIB_SUBMENU_H][ZLIB_SUBMENU_W+1] =
|
||||
//1. 5. 10. 15. 20. 25. 30. 35. 40.
|
||||
{ "||||||||||||||||||||||||||||||||||||||||",
|
||||
"| |",
|
||||
"| An error occurred when attempting to |",
|
||||
"| handle a compressed disk image: |",
|
||||
"| |",
|
||||
"| |",
|
||||
"||||||||||||||||||||||||||||||||||||||||" };
|
||||
|
||||
static void _eject_disk(int drive) {
|
||||
const char *err_str = c_eject_6(drive);
|
||||
if (err_str) {
|
||||
int ch = -1;
|
||||
snprintf(&zlibmenu[4][2], 37, "%s", err_str);
|
||||
c_interface_print_submenu_centered(zlibmenu[0], ZLIB_SUBMENU_W, ZLIB_SUBMENU_H);
|
||||
while ((ch = c_mygetch(1)) == -1) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_interface_select_diskette( int drive )
|
||||
{
|
||||
|
@ -563,9 +586,15 @@ void c_interface_select_diskette( int drive )
|
|||
/* reopen disk, forcing write enabled */
|
||||
if (toupper(ch) == 'W')
|
||||
{
|
||||
if (c_new_diskette_6(drive, temp, 0))
|
||||
const char *err_str = c_new_diskette_6(drive, temp, 0);
|
||||
if (err_str)
|
||||
{
|
||||
ERRLOG("Problem loading readonly disk image");
|
||||
int ch = -1;
|
||||
snprintf(&zlibmenu[4][2], 37, "%s", err_str);
|
||||
c_interface_print_submenu_centered(zlibmenu[0], ZLIB_SUBMENU_W, ZLIB_SUBMENU_H);
|
||||
while ((ch = c_mygetch(1)) == -1) {
|
||||
// ...
|
||||
}
|
||||
c_interface_print_screen( screen );
|
||||
continue;
|
||||
}
|
||||
|
@ -574,7 +603,7 @@ void c_interface_select_diskette( int drive )
|
|||
}
|
||||
|
||||
/* eject the disk and start over */
|
||||
c_eject_6(drive);
|
||||
_eject_disk(drive);
|
||||
c_interface_print_screen( screen );
|
||||
|
||||
nextdir = true;
|
||||
|
@ -612,12 +641,18 @@ void c_interface_select_diskette( int drive )
|
|||
break;
|
||||
}
|
||||
|
||||
c_eject_6(drive);
|
||||
_eject_disk(drive);
|
||||
c_interface_print_screen( screen );
|
||||
|
||||
if (c_new_diskette_6(drive, temp, (toupper(ch) != 'W')))
|
||||
const char *err_str = c_new_diskette_6(drive, temp, (toupper(ch) != 'W'));
|
||||
if (err_str)
|
||||
{
|
||||
ERRLOG("Problem loading disk image");
|
||||
int ch = -1;
|
||||
snprintf(&zlibmenu[4][2], 37, "%s", err_str);
|
||||
c_interface_print_submenu_centered(zlibmenu[0], ZLIB_SUBMENU_W, ZLIB_SUBMENU_H);
|
||||
while ((ch = c_mygetch(1)) == -1) {
|
||||
// ...
|
||||
}
|
||||
c_interface_print_screen( screen );
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user