mirror of
https://github.com/ivanizag/izapple2.git
synced 2026-10-22 00:02:27 +00:00
The emulation writes to a disk in the file it was loaded from, so saving a game modifies the image the user has. With a save directory the changes go to an overlay file there instead and the image is only ever read. An overlay stores just the parts the software wrote, indexed by a bitmap in its header: tracks of 4096 bytes for the diskettes, blocks of 512 for the ProDOS devices. Nothing is written for the rest, so the file takes as much space as what was saved and not the size of the disk, which matters for the hard disks where an image can be 32Mb and a saved game a handful of blocks. The header also holds a checksum of the image it was made from, so an overlay is never applied to a different disk with the same name. As the image is only read, this also makes writable the disks that could not be written at all: the ones inside a zip or a gzip, the ones loaded from an URL and the ones embedded in the executable. The directory comes from the new -saveDir option. The cards that write to their disks take a savedir parameter of their own that defaults to it, with 'none' to write back to the image. Also fixes saveTrack leaking a file descriptor on every track written, and going on to write through a nil file when it could not be opened.