Skip to content

Commit

Permalink
CORE: D81acces/F011-FDC API changes #140
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Mar 16, 2022
1 parent 6555634 commit 2b6b403
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
45 changes: 39 additions & 6 deletions xemu/d81access.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,21 +672,54 @@ Uint8 *d81access_create_image ( Uint8 *img, const char *diskname, const int name
diskname = diskname_default;
namelen = strlen(diskname_default);
}
unsigned int diskid = 0;
unsigned int diskid = namelen + ((namelen + 1) << 8);
DEBUGPRINT("D81ACCESS: creating memory image of a new D81 disk \"");
for (int i = 0; i < namelen; i++) {
for (unsigned int i = 0; i < namelen; i++) {
Uint8 c = (Uint8)diskname[i];
diskid += (unsigned int)c;
diskid += (unsigned int)c + (i << 5);
if (c >= 'a' && c <= 'z')
c -= 32;
else if (c < 32 || c >= 0x7F)
c = '?';
img[0x61804 + i] = c;
DEBUGPRINT("%c", c);
}
diskid = (diskid ^ (diskid >> 3)) % (26 * 26);
img[0x61816] = 'A' + (diskid / 26);
img[0x61817] = 'A' + (diskid % 26);
diskid = (diskid ^ (diskid >> 5));
for (unsigned int i = 0; i < 2; i++, diskid /= 36) {
const Uint8 c = diskid % 36;
img[0x61816 + i] = c < 26 ? c + 'A' : c - 26 + '0';
}
DEBUGPRINT("\",\"%c%c\"" NL, img[0x61816], img[0x61817]);
return img;
}


// Return values:
// 0 = OK, image created
// -1 = some error
// -2 = file existed before, and do_overwrite as not specified
int d81access_create_image_file ( const char *fn, const char *diskname, const int do_overwrite, const char *cry )
{
char fullpath[PATH_MAX + 1];
const int fd = xemu_open_file(fn, O_WRONLY | O_CREAT | O_TRUNC | (!do_overwrite ? O_EXCL : 0), NULL, fullpath);
if (fd < 0) {
const int ret = (errno == EEXIST) ? -2 : -1;
if (cry)
ERROR_WINDOW("%s [D81-CREATE]\n%s\n%s", cry, fn, strerror(errno));
if (ret == -2)
DEBUGPRINT("D81ACCESS: D81 image \"%s\" existed before." NL, fn);
return ret;
}
Uint8 *img = d81access_create_image(NULL, diskname ? diskname : fn, !diskname);
const int written = xemu_safe_write(fd, img, D81_SIZE);
xemu_os_close(fd);
free(img);
if (written != D81_SIZE) {
if (cry)
ERROR_WINDOW("%s [D81-WRITE]\n%s\n%s", cry, fullpath, strerror(errno));
xemu_os_unlink(fullpath);
return -1;
}
DEBUGPRINT("D81ACCESS: new disk image file \"%s\" has been successfully created (overwrite policy %d)." NL, fullpath, do_overwrite);
return 0;
}
1 change: 1 addition & 0 deletions xemu/d81access.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ extern void d81access_close_all ( void );
extern void d81access_attach_fd ( int which, int fd, off_t offset, int mode );
extern int d81access_attach_fsobj ( int which, const char *fn, int mode );
extern Uint8 *d81access_create_image ( Uint8 *img, const char *diskname, const int name_from_fn );
extern int d81access_create_image_file ( const char *fn, const char *diskname, const int do_overwrite, const char *cry );

#endif
8 changes: 8 additions & 0 deletions xemu/emutools.c
Original file line number Diff line number Diff line change
Expand Up @@ -1718,9 +1718,17 @@ int xemu_os_stat ( const char *fn, struct stat *statbuf )
return 0;
}


#endif


int xemu_os_file_exists ( const char *fn )
{
struct stat st;
return !xemu_os_stat(fn, &st);
}


#ifndef XEMU_ARCH_WIN
int xemu_os_readdir ( XDIR *dirp, char *fn )
{
Expand Down
1 change: 1 addition & 0 deletions xemu/emutools.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,6 @@ extern void sha1_checksum_as_string ( sha1_hash_str hash_str, const Uint8 *data,
#endif
#define xemu_os_close close
extern int xemu_os_readdir ( XDIR *dirp, char *fn );
extern int xemu_os_file_exists ( const char *fn );

#endif
24 changes: 24 additions & 0 deletions xemu/f011_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ void fdc_init ( Uint8 *cache_set )
}


int fdc_get_buffer_disk_address ( void )
{
return cache_p_fdc;
}


int fdc_get_buffer_cpu_address ( void )
{
return cache_p_cpu;
}


int fdc_get_status_a ( const int which )
{
return DRV_STATUS_A(which >= 0 ? which : drive);
}


int fdc_get_status_b ( const int which )
{
return DRV_STATUS_B(which >= 0 ? which : drive);
}


int fdc_get_led_state ( int blink_inc )
{
static unsigned int blink_counter = 0;
Expand Down
4 changes: 4 additions & 0 deletions xemu/f011_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ extern void fdc_init ( Uint8 *cache_set );
extern void fdc_set_disk ( int which, int in_have_disk, int in_have_write );
extern void fdc_allow_disk_access ( int in );
extern int fdc_get_led_state ( int blink_inc );
extern int fdc_get_buffer_cpu_address ( void );
extern int fdc_get_buffer_disk_address ( void );
extern int fdc_get_status_a ( const int which );
extern int fdc_get_status_b ( const int which );

/* must defined by the user */
extern int fdc_cb_rd_sec ( const int which, Uint8 *buffer, const Uint8 side, const Uint8 track, const Uint8 sector );
Expand Down

0 comments on commit 2b6b403

Please sign in to comment.