1
0
mirror of https://github.com/gryf/uc1541.git synced 2026-02-01 03:25:45 +01:00

Added support for .d81 images.

This commit is contained in:
2019-09-20 18:00:03 +02:00
parent 3fa965de85
commit 76daa17640
2 changed files with 36 additions and 16 deletions

View File

@@ -11,16 +11,16 @@ Features
======== ========
* view, remove, copy files in and out of the image * view, remove, copy files in and out of the image
* support for read from and write to d64 images * support for read from and write to d64, d71 and d81 images
* gzipped disk images support * gzipped disk images support
* onfly characters remapping (see below) * onfly characters remapping (see below)
Remarks Remarks
======= =======
Due to different way of representing file entries on regular D64 disk images, Due to different way of representing file entries on regular Commodore disk
there could be issues with filenames that are transfered from/to the image. images, there could be issues with filenames that are transfered from/to the
Following rules was applied to represent a single file entry: image. Following rules was applied to represent a single file entry:
1. An extension is attached to the end of a filename depending on a file type. 1. An extension is attached to the end of a filename depending on a file type.
Possible extensions are: ``prg``, ``del``, ``seq``, ``usr`` and ``rel``. Possible extensions are: ``prg``, ``del``, ``seq``, ``usr`` and ``rel``.
@@ -30,7 +30,7 @@ Following rules was applied to represent a single file entry:
3. Every slash character (``/``) will be replaced by pipe character (``|``). 3. Every slash character (``/``) will be replaced by pipe character (``|``).
4. Leading space will be replaced by tilda (``~``). 4. Leading space will be replaced by tilda (``~``).
While copying from D64 image to filesystem, filenames will be stored as they While copying from disk image to filesystem, filenames will be stored as they
are seen on a listing. are seen on a listing.
While copying from filesystem to D64 image, filename conversion will be done: While copying from filesystem to D64 image, filename conversion will be done:
@@ -43,8 +43,8 @@ While copying from filesystem to D64 image, filename conversion will be done:
Representation of a directory can be sometimes confusing - in case when one Representation of a directory can be sometimes confusing - in case when one
copied file without extension it stays there in such form, till next access copied file without extension it stays there in such form, till next access
(after flushing VFS). Also file sizes are not accurate, since D64 directory (after flushing VFS). Also file sizes are not accurate, since directory entries
entries have sizes stored as 256 bytes blocks. in CBM format have sizes stored as 256 bytes blocks.
Screens below shows how it looks like on real C64 machine and its representation Screens below shows how it looks like on real C64 machine and its representation
on Midnight Commander listing. on Midnight Commander listing.
@@ -67,7 +67,7 @@ Installation
* add or change entry for files handle in ``~/.config/mc/mc.ext``:: * add or change entry for files handle in ``~/.config/mc/mc.ext``::
# Disk images for Commodore computers (VIC20, C64, C128) # Disk images for Commodore computers (VIC20, C64, C128)
regex/\.(d64|D64|d6z|D6z|d6Z|D6Z)$ regex/\.([dD]64|[dD]6[zZ]|[dD]71|[dD]7[zZ]|[dD]81|[dD]8[zZ])$
Open=%cd %p/uc1541:// Open=%cd %p/uc1541://
View=%view{ascii} c1541 %f -list View=%view{ascii} c1541 %f -list
Extract=c1541 %f -extract Extract=c1541 %f -extract
@@ -87,6 +87,7 @@ script behaviour:
Changelog Changelog
========= =========
* **3.3** Added support for .d71 and .d81 disk images.
* **3.2** Changed shebang to ``python`` executable instead of ``python3`` * **3.2** Changed shebang to ``python`` executable instead of ``python3``
* **3.1** Argparse on Python3 have different behaviour, where if no subcommand * **3.1** Argparse on Python3 have different behaviour, where if no subcommand
is provided, it will pass anyway. Fixed. is provided, it will pass anyway. Fixed.

35
uc1541
View File

@@ -3,8 +3,8 @@
UC1541 Virtual filesystem UC1541 Virtual filesystem
Author: Roman 'gryf' Dobosz <gryf73@gmail.com> Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
Date: 2019-09-15 Date: 2019-09-20
Version: 3.2 Version: 3.3
Licence: BSD Licence: BSD
source: https://bitbucket.org/gryf/uc1541 source: https://bitbucket.org/gryf/uc1541
mirror: https://github.com/gryf/uc1541 mirror: https://github.com/gryf/uc1541
@@ -68,8 +68,9 @@ def _ord(string_or_int):
def _get_raw(dimage): def _get_raw(dimage):
"""Try to get contents of the D64 image either it's gzip compressed or """
not.""" Try to get contents of the D64 image either it's gzip compressed or not.
"""
raw = None raw = None
with gzip.open(dimage, 'rb') as fobj: with gzip.open(dimage, 'rb') as fobj:
# Although the common approach with gzipped files is to check the # Although the common approach with gzipped files is to check the
@@ -136,8 +137,8 @@ class Disk(object):
0b011: 'usr', 0b011: 'usr',
0b100: 'rel'} 0b100: 'rel'}
OFFSET_MAP = {}
DIR_TRACK = 18 DIR_TRACK = 18
DIR_SECTOR = 1
def __init__(self, raw): def __init__(self, raw):
""" """
@@ -188,8 +189,9 @@ class Disk(object):
return False return False
if self.next_track is None: if self.next_track is None:
LOG.debug("Going to the track: 18,1") LOG.debug("Going to the track: %s, %s", self.DIR_TRACK,
offset = self._get_offset(self.DIR_TRACK, 1) self.DIR_SECTOR)
offset = self._get_offset(self.DIR_TRACK, self.DIR_SECTOR)
else: else:
offset = self._get_offset(self.next_track, self.next_sector) offset = self._get_offset(self.next_track, self.next_sector)
LOG.debug("Going to the track: %s,%s", self.next_track, LOG.debug("Going to the track: %s,%s", self.next_track,
@@ -198,7 +200,7 @@ class Disk(object):
self.current_sector_data = self.raw[offset:offset + SECLEN] self.current_sector_data = self.raw[offset:offset + SECLEN]
# Guard for reading data out of bound - that happened for discs which # Guard for reading data out of bound - that happened for discs which
# store only raw data, even on 18 track # store only raw data, even on directory track
if not self.current_sector_data: if not self.current_sector_data:
return False return False
@@ -367,6 +369,23 @@ class D81(Disk):
""" """
Implement d81 directory reader Implement d81 directory reader
""" """
DIR_TRACK = 40
DIR_SECTOR = 3
FILE_TYPES = {0b000: 'del',
0b001: 'seq',
0b010: 'prg',
0b011: 'usr',
0b100: 'rel',
0b101: 'cbm'}
def _get_offset(self, track, sector):
"""
Return offset (in bytes) for specified track and sector. In d81 is
easy, since we have 80 tracks with 40 sectors for 256 bytes each.
"""
# we wan to go to the beginning (first sector) of the track, not it's
# max, so that we need to extract its amount.
return (track * 40 - 40) * SECLEN + sector * SECLEN
class Uc1541(object): class Uc1541(object):