Improving dual disk drive handling
r25459 by Rhialto:
I enabled up to DRIVE_NUM IEEE-488 drives, rather than 2 (in True Drive Emulation mode). In some places where they are enumerated, it is 4. The drives use their full 3 bits of jumpered drive number now, rather than just 1 bit.
I have also generalised code so as to allow another dual drive. Since dual drives currently use up two device numbers, it will use 10 and 11. I'm currently simplifying the methods for checking the dualness of a drive.
When that is done, I hope to have gained enough understanding of the code to remove the horrible hack of using 2 devices for a dual drive, and remove it. It looks like it will simplify a lot of code (including removing lots of code that I changed for allowing 2 dual drives). That will have some repercussions on the GUIs, since for every drive you may need to be able to attach two image files. It also would add an extra "drive" parameter (in addition to the current "unit" parameter) to a shedload of functions, although this is a pretty mechanical change. In fact, it is the GUI change that currently holds me back...
TODO: Think of some elegant way to represent settings for 8 floppy images (for 4 dual drives), without requiring all GUIs to be updated at once.
TODO: After that, I can rework the code to make dual drives more regular and hence allow 4 of them.
Improving dual disk drive handling
Currently, dual disk drives live a strange half / double life. Drive 1 of unit 8 (using the terminology of Basic 4 and confusingly, only in some of the code) is using most of the data structures that would otherwise be used by unit 9. So if you want 2 dual drive units, they will have unit numbers 8 and 10.
This madness is clearly visible in source file src/drive/ieee/fdc.c.
There are 4 fdc_t structures, each of which corresponds to a drive. (Despite the name that suggests floppy disk controller). When using unit 9 or 11, or num_drives is 2, weird stuff happens in functions like fdc_reset().
My proposal here is to change all functions here that take a unit number (in particular those that also do something with a disk_image_t)(starting in drive/ieee/fdc.c), and change them to take a drive number too.. static fdc_t fdc[NUM_FDC]; will become static fdc_t fdc[NUM_FDC][2]; and the drive number will be the second index.
This change will flow outwards like an oil spill, since many functions are used via pointers and need to have the same signature, or call a function that needs a drive number, so they need a new parameter too... so the compiler will easily tell you what more has to be changed (and I didn't really research how far this will extend). Possibly, at some point, changes will be required at a point where you think "this is getting really really far from the starting point" and then maybe some creativity will be required.
For dual drives, there must be some code to reset both drives, if the unit is reset, for instance. I'm not sure where such things currently happen, but it may need to be moved.
Other weird things:
- struct drive_context_s refers to struct drive_s which refers to a struct disk_image_s, but fdc also refers to such a thing, and so does (for 2 types of disk controllers) context->wd1770->fdd->image, and context->pc4877->fdds[0]->fdd->image and context->pc4877->fdd->image and context->pc4877->current->fdd->image
- but there is no context->fdc. The fdc structs are accessed by number which is probably picked up from context->mynumber. Making this more similar to wd1770 and pc4877 is a separate change.
- Should there be 2 drive_contexts for dual drives, or just one which refers to 2 disk_image_s? If there should be 2, then where are these aggregated? (drive_context_s seems to be more a unit context, or drive as in device)
- Most of the things in drive_t (drive_context points to one) are indeed per-drive, but some also belong to the unit (such as parallel_cable, drive_ram2_enabled, rom and some more.
- Maybe drive_context_s should be renamed to unit_context_s, with pointers to 2 drive_ts, and some items moved from drive_t to unit_context.
- But there are so many uses of drive to mean the unit / device, maybe drive in the other meaning should be renamed. But what would be a good name??? "mech", short for drive mechanism???
here andre fachat posted some patch: https://sourceforge.net/p/vice-emu/feature-requests/314/