mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Compare commits
27 Commits
FluxEngine
...
FluxEngine
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b4a8d6de2 | ||
|
|
e8f7b51aef | ||
|
|
9d6bc57a5f | ||
|
|
73766f92b4 | ||
|
|
80badf3b54 | ||
|
|
116529f85a | ||
|
|
5a2b2bc07a | ||
|
|
41070395c0 | ||
|
|
4304d1eede | ||
|
|
46f1b0aef4 | ||
|
|
9923d67a7c | ||
|
|
99335a84fd | ||
|
|
c266779433 | ||
|
|
bdcc12cd53 | ||
|
|
7988d0fe24 | ||
|
|
27f5c294b1 | ||
|
|
b9a53e0d1c | ||
|
|
f8b6d5e6fb | ||
|
|
04ff31c348 | ||
|
|
77b4aebd1b | ||
|
|
4056364300 | ||
|
|
60bfe050d3 | ||
|
|
28d0ce765e | ||
|
|
4954d33307 | ||
|
|
55f3354287 | ||
|
|
d6ae373fa8 | ||
|
|
a626d5f9a0 |
@@ -15,7 +15,7 @@ install:
|
||||
|
||||
build_script:
|
||||
- make
|
||||
- zip -9 fluxengine.zip fluxengine.exe brother120tool.exe
|
||||
- zip -9 fluxengine.zip fluxengine.exe brother120tool.exe FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex
|
||||
|
||||
artifacts:
|
||||
- path: fluxengine.zip
|
||||
|
||||
4626
FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex
Normal file
4626
FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex
Normal file
File diff suppressed because it is too large
Load Diff
@@ -530,31 +530,38 @@
|
||||
<CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize" version="3">
|
||||
<CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtBaseContainerSerialize" version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED" persistent="">
|
||||
<Hidden v="False" />
|
||||
<Hidden v="True" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<CyGuid_0820c2e7-528d-4137-9a08-97257b946089 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemListSerialize" version="2">
|
||||
<dependencies>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_aliases.h" persistent="Generated_Source\PSoC5\LED_aliases.h">
|
||||
<Hidden v="False" />
|
||||
<Hidden v="True" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="HEADER;;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED.c" persistent="Generated_Source\PSoC5\LED.c">
|
||||
<Hidden v="False" />
|
||||
<Hidden v="True" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="SOURCE_C;CortexM3;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED.h" persistent="Generated_Source\PSoC5\LED.h">
|
||||
<Hidden v="False" />
|
||||
<Hidden v="True" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="HEADER;;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_PM.c" persistent="Generated_Source\PSoC5\LED_PM.c">
|
||||
<Hidden v="True" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="SOURCE_C;CortexM3;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
</dependencies>
|
||||
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
|
||||
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
|
||||
@@ -3282,6 +3289,39 @@
|
||||
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
|
||||
<filters />
|
||||
</CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0>
|
||||
<CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize" version="3">
|
||||
<CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtBaseContainerSerialize" version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_PIN" persistent="">
|
||||
<Hidden v="False" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<CyGuid_0820c2e7-528d-4137-9a08-97257b946089 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemListSerialize" version="2">
|
||||
<dependencies>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_PIN_aliases.h" persistent="Generated_Source\PSoC5\LED_PIN_aliases.h">
|
||||
<Hidden v="False" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="HEADER;;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_PIN.c" persistent="Generated_Source\PSoC5\LED_PIN.c">
|
||||
<Hidden v="False" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="SOURCE_C;CortexM3;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
|
||||
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="LED_PIN.h" persistent="Generated_Source\PSoC5\LED_PIN.h">
|
||||
<Hidden v="False" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="HEADER;;;;" />
|
||||
<PropertyDeltas />
|
||||
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
|
||||
</dependencies>
|
||||
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
|
||||
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
|
||||
<filters />
|
||||
</CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0>
|
||||
</dependencies>
|
||||
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
|
||||
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
|
||||
@@ -3700,6 +3740,6 @@
|
||||
</ignored_deps>
|
||||
</CyGuid_495451fe-d201-4d01-b22d-5d3f5609ac37>
|
||||
<boot_component v="" />
|
||||
<current_generation v="60" />
|
||||
<current_generation v="68" />
|
||||
</CyGuid_fec8f9e8-2365-4bdb-96d3-a4380222e01b>
|
||||
</CyXmlSerializer>
|
||||
Binary file not shown.
Binary file not shown.
4
Makefile
4
Makefile
@@ -1,8 +1,8 @@
|
||||
PACKAGES = zlib sqlite3 libusb-1.0
|
||||
|
||||
export CFLAGS = -O3 -g --std=c++14 \
|
||||
export CFLAGS = -Os -g --std=c++14 \
|
||||
-ffunction-sections -fdata-sections
|
||||
export LDFLAGS = -O3
|
||||
export LDFLAGS = -Os
|
||||
|
||||
ifeq ($(OS), Windows_NT)
|
||||
export CXX = /mingw32/bin/g++
|
||||
|
||||
@@ -134,6 +134,9 @@ void IbmDecoder::decodeSectorRecord()
|
||||
uint16_t gotCrc = crc16(CCITT_POLY, bytes.slice(0, _currentHeaderLength + 5));
|
||||
if (wantCrc == gotCrc)
|
||||
_sector->status = Sector::DATA_MISSING; /* correct but unintuitive */
|
||||
|
||||
if (_ignoreSideByte)
|
||||
_sector->logicalSide = _sector->physicalSide;
|
||||
}
|
||||
|
||||
void IbmDecoder::decodeDataRecord()
|
||||
|
||||
@@ -31,8 +31,9 @@ struct IbmIdam
|
||||
class IbmDecoder : public AbstractDecoder
|
||||
{
|
||||
public:
|
||||
IbmDecoder(unsigned sectorBase):
|
||||
_sectorBase(sectorBase)
|
||||
IbmDecoder(unsigned sectorBase, bool ignoreSideByte=false):
|
||||
_sectorBase(sectorBase),
|
||||
_ignoreSideByte(ignoreSideByte)
|
||||
{}
|
||||
|
||||
RecordType advanceToNextRecord();
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
unsigned _sectorBase;
|
||||
bool _ignoreSideByte;
|
||||
unsigned _currentSectorSize;
|
||||
unsigned _currentHeaderLength;
|
||||
};
|
||||
|
||||
@@ -103,7 +103,43 @@ the unconnected pins and solder a short piece of wire to a GND pin on the
|
||||
board. Alternatively you'll need to splice it into your drive's power supply
|
||||
cable somehow. (The black one.)
|
||||
|
||||
## Building the firmware
|
||||
## Programming the board
|
||||
|
||||
You've got two options here. You can either use the precompiled firmware
|
||||
supplied with the source, or else install the Cypress SDK and build it
|
||||
yourself. If you want to hack the firmware source you need the latter, but
|
||||
if you trust me to do it for you use the precompiled firmware. In either
|
||||
case you'll need Windows and have to install some Cypress stuff.
|
||||
|
||||
**Before you read this:** If you're on Windows, good news! You can download a
|
||||
precompiled version of the FluxEngine client and precompiled firmware [from
|
||||
the GitHub releases
|
||||
page](https://github.com/davidgiven/fluxengine/releases/latest). Simply unzip
|
||||
it somewhere and run the `.exe` files from a `cmd` window (or other shell).
|
||||
Follow the instructions below to program the board with the firmware.
|
||||
|
||||
### Using the precompiled firmware
|
||||
|
||||
On your Windows machine, [install the PSoC
|
||||
Programmer](https://www.cypress.com/products/psoc-programming-solutions).
|
||||
**Note:** _not_ the Cypress Programmer, which is for a different board!
|
||||
Cypress will make you register.
|
||||
|
||||
Once done, run it. Plug the blunt end of the FluxEngine board into a USB
|
||||
port (the end which is a USB connector). The programmer should detect it
|
||||
and report it as a KitProg. You may be prompted to upgrade the programmer
|
||||
hardware; if so, follow the instructions and do it.
|
||||
|
||||
Now go to File -> File Load and open
|
||||
`FluxEngine.cydsn/CortexM3/ARM_GCC_541/Release/FluxEngine.hex` in the
|
||||
project. If you're on Windows, the precompiled zipfile also contains a copy
|
||||
of this file. Press the Program button (the one in the toolbar marked with a
|
||||
down arrow). Stuff will happen and you should be left with three green boxes
|
||||
in the status bar and 'Programming Succeeded' at the top of the log window.
|
||||
|
||||
You're done. You can unplug the board and close the programmer.
|
||||
|
||||
### Building the firmware yourself
|
||||
|
||||
On your Windows machine, [install the Cypress SDK and CY8CKIT-059
|
||||
BSP](http://www.cypress.com/documentation/development-kitsboards/cy8ckit-059-psoc-5lp-prototyping-kit-onboard-programmer-and).
|
||||
@@ -118,7 +154,7 @@ tutorial and making the LED on your board flash. It'll tell you where all the
|
||||
controls are and how to program the board. Remember that the big end of the
|
||||
board plugs into your computer for programming.
|
||||
|
||||
When you're ready, open the `FluxEngine.cydsn/FluxEngine.cywrk` workspace,
|
||||
When you're ready, open the `FluxEngine.cydsn/FluxEngine.cyprj` project,
|
||||
pick 'Program' from the menu, and the firmware should compile and be
|
||||
programmed onto your board.
|
||||
|
||||
@@ -139,11 +175,6 @@ the port and proceed normally.
|
||||
|
||||
## Building the client
|
||||
|
||||
**Before you read this:** If you're on Windows, good news! You can download a
|
||||
*precompiled version of the FluxEngine client [from the GitHub releases
|
||||
*page](https://github.com/davidgiven/fluxengine/releases/latest). Simply unzip
|
||||
*it somewhere and run it from a `cmd` window (or other shell).
|
||||
|
||||
The client software is where the intelligence, such as it is, is. It's pretty
|
||||
generic libusb stuff and should build and run on Windows, Linux and OSX as
|
||||
well, although on Windows it'll need MSYS2 and mingw32. You'll need to
|
||||
|
||||
@@ -23,7 +23,7 @@ computer](https://ilesj.wordpress.com/2014/05/14/1541-why-so-complicated/) of
|
||||
300 bytes per second (!). (The drive itself could transfer data reasonably
|
||||
quickly.)
|
||||
|
||||
A standard 1541 disk has 35 tracks of 17 to 20 sectors, each 256 bytes long.
|
||||
A standard 1541 disk has 35 tracks of 17 to 21 sectors, each 256 bytes long.
|
||||
|
||||
Reading discs
|
||||
-------------
|
||||
@@ -34,15 +34,14 @@ Just do:
|
||||
fluxengine read c64
|
||||
```
|
||||
|
||||
You should end up with an `c64.img` which is 187136 bytes long (for a normal
|
||||
1541 disk).
|
||||
You should end up with an `c64.d64` file which is 174848 bytes long. You can
|
||||
load this straight into a Commodore 64 emulator such as
|
||||
[VICE](http://vice-emu.sourceforge.net/).
|
||||
|
||||
**Big warning!** The image may not work in an emulator. Commodore 64 disk images are
|
||||
**Big warning!** Commodore 64 disk images are
|
||||
complicated due to the way the tracks are different sizes and the odd sector
|
||||
size. FluxEngine chooses to store them in a simple 256 x 20 x 35 layout,
|
||||
with holes where missing sectors should be. This was easiest. If anyone can
|
||||
suggest a better way, please [get in
|
||||
touch](https://github.com/davidgiven/fluxengine/issues/new).
|
||||
size, so you need the special D64 or LDBS output formats to represent them
|
||||
sensibly. Don't use IMG unless you know what you're doing.
|
||||
|
||||
Useful references
|
||||
-----------------
|
||||
|
||||
53
doc/using.md
53
doc/using.md
@@ -148,6 +148,15 @@ based on the extension:
|
||||
it doesn't store a lot of the more esoteric LDBS features like format
|
||||
types, timings, and data rates.
|
||||
|
||||
- `.d64`: the venerable Commodore 64 disk image format as used by the 1540,
|
||||
1541, etc. This is a special-purpose format due to the weird layout of
|
||||
1540 disks and while you can use this for non-Commodore disks the result
|
||||
will be gibberish. Use this to image Commodore 64 disks and load the
|
||||
result into an emulator.
|
||||
|
||||
FluxEngine's D64 support is currently limited to write only. It will work
|
||||
with up to 40 logical tracks.
|
||||
|
||||
### High density disks
|
||||
|
||||
High density disks use a different magnetic medium to low and double density
|
||||
@@ -212,10 +221,39 @@ directory.
|
||||
file format in a non-backwards-compatible way; this tool will upgrade flux
|
||||
files to the new format.
|
||||
|
||||
- `fluxengine convert`: converts flux files from various formats to various
|
||||
other formats. You can use this to convert Catweasel flux files to
|
||||
FluxEngine's native format, FluxEngine flux files to various other formats
|
||||
useful for debugging (including VCD which can be loaded into
|
||||
[sigrok](http://sigrok.org)), and bidirectional conversion to and from
|
||||
Supercard Pro `.scp` format.
|
||||
|
||||
**Important SCP note:** import (`fluxengine convert scptoflux`) should be
|
||||
fairly robust, but export (`fluxengine convert fluxtoscp`) should only be
|
||||
done with great caution as FluxEngine files contain features which can't be
|
||||
represented very well in `.scp` format and they're probably pretty dubious.
|
||||
As ever, please [get in
|
||||
touch](https://github.com/davidgiven/fluxengine/issues/new) with any reports.
|
||||
|
||||
Commands which normally take `--source` or `--dest` get a sensible default if
|
||||
left unspecified. `fluxengine read ibm` on its own will read drive 0 and
|
||||
write an `ibm.img` file.
|
||||
|
||||
## Visualisation
|
||||
|
||||
When doing a read (either from a real disk or from a flux file) you can use
|
||||
`--write-svg=output.svg` to write out a graphical visualisation of where the
|
||||
sectors are on the disk. Here's a IBM PC 1232kB disk:
|
||||
|
||||

|
||||
|
||||
Blue represents data, light blue a header, and red is a bad sector. Side zero
|
||||
is on the left and side one is on the right.
|
||||
|
||||
The visualiser is extremely primitive and you have to explicitly tell it how
|
||||
big your disk is, in milliseconds. The default is 200ms (for a normal 3.5"
|
||||
disk). For a 5.25" disk, use `--visualiser-period=166`.
|
||||
|
||||
## Extra programs
|
||||
|
||||
Supplied with FluxEngine, but not part of FluxEngine, are some little tools I
|
||||
@@ -223,25 +261,24 @@ wrote to do useful things. These are built alongside FluxEngine.
|
||||
|
||||
- `brother120tool`: extracts files from a 120kB Brother filesystem image.
|
||||
|
||||
- `cwftoflux`: converts (one flavour of) CatWeasel flux file into a
|
||||
FluxEngine flux file.
|
||||
|
||||
## The recommended workflow
|
||||
|
||||
So you've just received, say, a huge pile of old Brother word processor disks containing valuable historical data, and you want to read them.
|
||||
So you've just received, say, a huge pile of old Brother word processor disks
|
||||
containing valuable historical data, and you want to read them.
|
||||
|
||||
Typically I do this:
|
||||
|
||||
```
|
||||
$ fluxengine read brother -s :d=0 -o brother.img --write-flux=brother.flux
|
||||
$ fluxengine read brother -s :d=0 -o brother.img --write-flux=brother.flux --write-svg=brother.svg
|
||||
```
|
||||
|
||||
This will read the disk in drive 0 and write out a filesystem image. It'll
|
||||
also copy the flux to brother.flux. If I then need to tweak the settings, I
|
||||
can rerun the decode without having to physically touch the disk like this:
|
||||
also copy the flux to brother.flux and write out an SVG visualisation. If I
|
||||
then need to tweak the settings, I can rerun the decode without having to
|
||||
physically touch the disk like this:
|
||||
|
||||
```
|
||||
$ fluxengine read brother -s brother.flux -o brother.img
|
||||
$ fluxengine read brother -s brother.flux -o brother.img --write-svg=brother.svg
|
||||
```
|
||||
|
||||
Apart from being drastically faster, this avoids touching the (potentially
|
||||
|
||||
1
doc/visualiser.svg
Normal file
1
doc/visualiser.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 394 KiB |
@@ -43,19 +43,25 @@ void AbstractDecoder::decodeToSectors(Track& track)
|
||||
|
||||
recordStart = fmr.tell();
|
||||
decodeSectorRecord();
|
||||
pushRecord(recordStart, fmr.tell());
|
||||
Fluxmap::Position recordEnd = fmr.tell();
|
||||
pushRecord(recordStart, recordEnd);
|
||||
if (sector.status == Sector::DATA_MISSING)
|
||||
{
|
||||
/* The data is in a separate record. */
|
||||
|
||||
sector.headerStartTime = recordStart.ns();
|
||||
sector.headerEndTime = recordEnd.ns();
|
||||
r = advanceToNextRecord();
|
||||
if (r == DATA_RECORD)
|
||||
{
|
||||
recordStart = fmr.tell();
|
||||
decodeDataRecord();
|
||||
pushRecord(recordStart, fmr.tell());
|
||||
recordEnd = fmr.tell();
|
||||
pushRecord(recordStart, recordEnd);
|
||||
}
|
||||
}
|
||||
sector.dataStartTime = recordStart.ns();
|
||||
sector.dataEndTime = recordEnd.ns();
|
||||
|
||||
if (sector.status != Sector::MISSING)
|
||||
track.sectors.push_back(sector);
|
||||
|
||||
88
lib/flags.cc
88
lib/flags.cc
@@ -29,7 +29,7 @@ void FlagGroup::addFlag(Flag* flag)
|
||||
_flags.push_back(flag);
|
||||
}
|
||||
|
||||
void FlagGroup::parseFlags(int argc, const char* argv[])
|
||||
std::vector<std::string> FlagGroup::parseFlagsWithFilenames(int argc, const char* argv[])
|
||||
{
|
||||
if (_initialised)
|
||||
throw std::runtime_error("called parseFlags() twice");
|
||||
@@ -66,6 +66,7 @@ void FlagGroup::parseFlags(int argc, const char* argv[])
|
||||
|
||||
/* Now actually parse them. */
|
||||
|
||||
std::vector<std::string> filenames;
|
||||
int index = 1;
|
||||
while (index < argc)
|
||||
{
|
||||
@@ -76,52 +77,73 @@ void FlagGroup::parseFlags(int argc, const char* argv[])
|
||||
std::string value;
|
||||
bool usesthat = false;
|
||||
|
||||
if ((thisarg.size() == 0) || (thisarg[0] != '-'))
|
||||
Error() << "non-option parameter " << thisarg << " seen (try --help)";
|
||||
if ((thisarg.size() > 1) && (thisarg[1] == '-'))
|
||||
if (thisarg.size() == 0)
|
||||
{
|
||||
/* Long option. */
|
||||
|
||||
auto equals = thisarg.rfind('=');
|
||||
if (equals != std::string::npos)
|
||||
{
|
||||
key = thisarg.substr(0, equals);
|
||||
value = thisarg.substr(equals+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = thisarg;
|
||||
value = thatarg;
|
||||
usesthat = true;
|
||||
}
|
||||
/* Ignore this argument. */
|
||||
}
|
||||
else if (thisarg[0] != '-')
|
||||
{
|
||||
/* This is a filename. */
|
||||
filenames.push_back(thisarg);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Short option. */
|
||||
/* This is a flag. */
|
||||
|
||||
if (thisarg.size() > 2)
|
||||
if ((thisarg.size() > 1) && (thisarg[1] == '-'))
|
||||
{
|
||||
key = thisarg.substr(0, 2);
|
||||
value = thisarg.substr(2);
|
||||
/* Long option. */
|
||||
|
||||
auto equals = thisarg.rfind('=');
|
||||
if (equals != std::string::npos)
|
||||
{
|
||||
key = thisarg.substr(0, equals);
|
||||
value = thisarg.substr(equals+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = thisarg;
|
||||
value = thatarg;
|
||||
usesthat = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
key = thisarg;
|
||||
value = thatarg;
|
||||
usesthat = true;
|
||||
/* Short option. */
|
||||
|
||||
if (thisarg.size() > 2)
|
||||
{
|
||||
key = thisarg.substr(0, 2);
|
||||
value = thisarg.substr(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = thisarg;
|
||||
value = thatarg;
|
||||
usesthat = true;
|
||||
}
|
||||
}
|
||||
|
||||
auto flag = flags_by_name.find(key);
|
||||
if (flag == flags_by_name.end())
|
||||
Error() << "unknown flag '" << key << "'; try --help";
|
||||
|
||||
flag->second->set(value);
|
||||
if (usesthat && flag->second->hasArgument())
|
||||
index++;
|
||||
}
|
||||
|
||||
auto flag = flags_by_name.find(key);
|
||||
if (flag == flags_by_name.end())
|
||||
Error() << "unknown flag '" << key << "'; try --help";
|
||||
|
||||
flag->second->set(value);
|
||||
|
||||
index++;
|
||||
if (usesthat && flag->second->hasArgument())
|
||||
index++;
|
||||
}
|
||||
|
||||
return filenames;
|
||||
}
|
||||
|
||||
void FlagGroup::parseFlags(int argc, const char* argv[])
|
||||
{
|
||||
auto filenames = parseFlagsWithFilenames(argc, argv);
|
||||
if (!filenames.empty())
|
||||
Error() << "non-option parameter " << *filenames.begin() << " seen (try --help)";
|
||||
}
|
||||
|
||||
void FlagGroup::checkInitialised() const
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
|
||||
public:
|
||||
void parseFlags(int argc, const char* argv[]);
|
||||
std::vector<std::string> parseFlagsWithFilenames(int argc, const char* argv[]);
|
||||
void addFlag(Flag* flag);
|
||||
void checkInitialised() const;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
void recalibrate() {}
|
||||
|
||||
private:
|
||||
const std::string& _path;
|
||||
const std::string _path;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createStreamFluxSource(const std::string& path)
|
||||
|
||||
@@ -22,7 +22,7 @@ extern void hexdumpForSrp16(std::ostream& stream, const Bytes& bytes);
|
||||
class Error
|
||||
{
|
||||
public:
|
||||
~Error()
|
||||
[[ noreturn ]] ~Error()
|
||||
{
|
||||
std::cerr << "Error: " << _stream.str() << std::endl;
|
||||
exit(1);
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
std::map<std::string, ImageReader::Constructor> ImageReader::formats =
|
||||
{
|
||||
{".adf", ImageReader::createImgImageReader},
|
||||
{".d81", ImageReader::createImgImageReader},
|
||||
{".img", ImageReader::createImgImageReader},
|
||||
};
|
||||
|
||||
static bool ends_with(const std::string& value, const std::string& ending)
|
||||
{
|
||||
if (ending.size() > value.size())
|
||||
@@ -14,15 +21,29 @@ static bool ends_with(const std::string& value, const std::string& ending)
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageReader> ImageReader::create(const ImageSpec& spec)
|
||||
ImageReader::Constructor ImageReader::findConstructor(const ImageSpec& spec)
|
||||
{
|
||||
const auto& filename = spec.filename;
|
||||
|
||||
if (ends_with(filename, ".img") || ends_with(filename, ".adf"))
|
||||
return createImgImageReader(spec);
|
||||
for (const auto& e : formats)
|
||||
{
|
||||
if (ends_with(filename, e.first))
|
||||
return e.second;
|
||||
}
|
||||
|
||||
Error() << "unrecognised image filename extension";
|
||||
return std::unique_ptr<ImageReader>();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageReader> ImageReader::create(const ImageSpec& spec)
|
||||
{
|
||||
verifyImageSpec(spec);
|
||||
return findConstructor(spec)(spec);
|
||||
}
|
||||
|
||||
void ImageReader::verifyImageSpec(const ImageSpec& spec)
|
||||
{
|
||||
if (!findConstructor(spec))
|
||||
Error() << "unrecognised image filename extension";
|
||||
}
|
||||
|
||||
ImageReader::ImageReader(const ImageSpec& spec):
|
||||
|
||||
@@ -12,10 +12,21 @@ public:
|
||||
|
||||
public:
|
||||
static std::unique_ptr<ImageReader> create(const ImageSpec& spec);
|
||||
static void verifyImageSpec(const ImageSpec& spec);
|
||||
|
||||
private:
|
||||
typedef
|
||||
std::function<
|
||||
std::unique_ptr<ImageReader>(const ImageSpec& spec)
|
||||
>
|
||||
Constructor;
|
||||
|
||||
static std::map<std::string, Constructor> formats;
|
||||
|
||||
static std::unique_ptr<ImageReader> createImgImageReader(const ImageSpec& spec);
|
||||
|
||||
static Constructor findConstructor(const ImageSpec& spec);
|
||||
|
||||
public:
|
||||
virtual SectorSet readImage() = 0;
|
||||
|
||||
|
||||
64
lib/imagewriter/d64imagewriter.cc
Normal file
64
lib/imagewriter/d64imagewriter.cc
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "globals.h"
|
||||
#include "image.h"
|
||||
#include "flags.h"
|
||||
#include "dataspec.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagewriter/imagewriter.h"
|
||||
#include "fmt/format.h"
|
||||
#include "ldbs.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
static int sectors_per_track(int track)
|
||||
{
|
||||
if (track < 17)
|
||||
return 21;
|
||||
if (track < 24)
|
||||
return 19;
|
||||
if (track < 30)
|
||||
return 18;
|
||||
return 17;
|
||||
}
|
||||
|
||||
class D64ImageWriter : public ImageWriter
|
||||
{
|
||||
public:
|
||||
D64ImageWriter(const SectorSet& sectors, const ImageSpec& spec):
|
||||
ImageWriter(sectors, spec)
|
||||
{}
|
||||
|
||||
void writeImage()
|
||||
{
|
||||
std::cout << "writing D64 triangular image\n";
|
||||
|
||||
std::ofstream outputFile(spec.filename, std::ios::out | std::ios::binary);
|
||||
if (!outputFile.is_open())
|
||||
Error() << "cannot open output file";
|
||||
|
||||
uint32_t offset = 0;
|
||||
for (int track = 0; track < 40; track++)
|
||||
{
|
||||
int sectorCount = sectors_per_track(track);
|
||||
for (int sectorId = 0; sectorId < sectorCount; sectorId++)
|
||||
{
|
||||
const auto& sector = sectors.get(track, 0, sectorId);
|
||||
if (sector)
|
||||
{
|
||||
outputFile.seekp(offset);
|
||||
outputFile.write((const char*) sector->data.cbegin(), 256);
|
||||
}
|
||||
|
||||
offset += 256;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<ImageWriter> ImageWriter::createD64ImageWriter(
|
||||
const SectorSet& sectors, const ImageSpec& spec)
|
||||
{
|
||||
return std::unique_ptr<ImageWriter>(new D64ImageWriter(sectors, spec));
|
||||
}
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
#include "imagewriter/imagewriter.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
std::map<std::string, ImageWriter::Constructor> ImageWriter::formats =
|
||||
{
|
||||
{".adf", ImageWriter::createImgImageWriter},
|
||||
{".d64", ImageWriter::createD64ImageWriter},
|
||||
{".d81", ImageWriter::createImgImageWriter},
|
||||
{".img", ImageWriter::createImgImageWriter},
|
||||
{".ldbs", ImageWriter::createLDBSImageWriter},
|
||||
};
|
||||
|
||||
static bool ends_with(const std::string& value, const std::string& ending)
|
||||
{
|
||||
if (ending.size() > value.size())
|
||||
@@ -14,17 +23,29 @@ static bool ends_with(const std::string& value, const std::string& ending)
|
||||
return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageWriter> ImageWriter::create(const SectorSet& sectors, const ImageSpec& spec)
|
||||
ImageWriter::Constructor ImageWriter::findConstructor(const ImageSpec& spec)
|
||||
{
|
||||
const auto& filename = spec.filename;
|
||||
|
||||
if (ends_with(filename, ".img") || ends_with(filename, ".adf"))
|
||||
return createImgImageWriter(sectors, spec);
|
||||
else if (ends_with(filename, ".ldbs"))
|
||||
return createLDBSImageWriter(sectors, spec);
|
||||
for (const auto& e : formats)
|
||||
{
|
||||
if (ends_with(filename, e.first))
|
||||
return e.second;
|
||||
}
|
||||
|
||||
Error() << "unrecognised image filename extension";
|
||||
return std::unique_ptr<ImageWriter>();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageWriter> ImageWriter::create(const SectorSet& sectors, const ImageSpec& spec)
|
||||
{
|
||||
verifyImageSpec(spec);
|
||||
return findConstructor(spec)(sectors, spec);
|
||||
}
|
||||
|
||||
void ImageWriter::verifyImageSpec(const ImageSpec& spec)
|
||||
{
|
||||
if (!findConstructor(spec))
|
||||
Error() << "unrecognised image filename extension";
|
||||
}
|
||||
|
||||
ImageWriter::ImageWriter(const SectorSet& sectors, const ImageSpec& spec):
|
||||
|
||||
@@ -12,12 +12,25 @@ public:
|
||||
|
||||
public:
|
||||
static std::unique_ptr<ImageWriter> create(const SectorSet& sectors, const ImageSpec& spec);
|
||||
static void verifyImageSpec(const ImageSpec& filename);
|
||||
|
||||
private:
|
||||
typedef
|
||||
std::function<
|
||||
std::unique_ptr<ImageWriter>(const SectorSet& sectors, const ImageSpec& spec)
|
||||
>
|
||||
Constructor;
|
||||
|
||||
static std::map<std::string, Constructor> formats;
|
||||
|
||||
static std::unique_ptr<ImageWriter> createImgImageWriter(
|
||||
const SectorSet& sectors, const ImageSpec& spec);
|
||||
static std::unique_ptr<ImageWriter> createLDBSImageWriter(
|
||||
const SectorSet& sectors, const ImageSpec& spec);
|
||||
static std::unique_ptr<ImageWriter> createD64ImageWriter(
|
||||
const SectorSet& sectors, const ImageSpec& spec);
|
||||
|
||||
static Constructor findConstructor(const ImageSpec& spec);
|
||||
|
||||
public:
|
||||
virtual void adjustGeometry();
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
#include "decoders/decoders.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "visualiser.h"
|
||||
#include "record.h"
|
||||
#include "image.h"
|
||||
#include "bytes.h"
|
||||
#include "decoders/rawbits.h"
|
||||
#include "track.h"
|
||||
#include "imagewriter/imagewriter.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
FlagGroup readerFlags { &hardwareFluxSourceFlags, &fluxmapReaderFlags };
|
||||
FlagGroup readerFlags { &hardwareFluxSourceFlags, &fluxmapReaderFlags, &visualiserFlags };
|
||||
|
||||
static DataSpecFlag source(
|
||||
{ "--source", "-s" },
|
||||
@@ -33,6 +35,11 @@ static StringFlag destination(
|
||||
"write the raw magnetic flux to this file",
|
||||
"");
|
||||
|
||||
static StringFlag visualise(
|
||||
{ "--write-svg" },
|
||||
"write a visualisation of the disk to this file",
|
||||
"");
|
||||
|
||||
static SettableFlag justRead(
|
||||
{ "--just-read" },
|
||||
"just read the disk and do no further processing");
|
||||
@@ -142,7 +149,7 @@ static void replace_sector(std::unique_ptr<Sector>& replacing, Sector& replaceme
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!replacing || (replacing->status != Sector::OK))
|
||||
if (!replacing || ((replacing->status != Sector::OK) && (replacement.status == Sector::OK)))
|
||||
{
|
||||
if (!replacing)
|
||||
replacing.reset(new Sector);
|
||||
@@ -153,7 +160,8 @@ static void replace_sector(std::unique_ptr<Sector>& replacing, Sector& replaceme
|
||||
void readDiskCommand(AbstractDecoder& decoder)
|
||||
{
|
||||
const ImageSpec outputSpec(output);
|
||||
|
||||
ImageWriter::verifyImageSpec(outputSpec);
|
||||
|
||||
bool failures = false;
|
||||
SectorSet allSectors;
|
||||
auto tracks = readTracks();
|
||||
@@ -251,6 +259,9 @@ void readDiskCommand(AbstractDecoder& decoder)
|
||||
std::cout << size << " bytes decoded." << std::endl;
|
||||
}
|
||||
|
||||
if (!visualise.get().empty())
|
||||
visualiseSectorsToFile(allSectors, visualise.get());
|
||||
|
||||
writeSectorsToFile(allSectors, outputSpec);
|
||||
if (failures)
|
||||
std::cerr << "Warning: some sectors could not be decoded." << std::endl;
|
||||
|
||||
@@ -27,6 +27,10 @@ public:
|
||||
Status status = Status::INTERNAL_ERROR;
|
||||
Fluxmap::Position position;
|
||||
nanoseconds_t clock = 0;
|
||||
nanoseconds_t headerStartTime = 0;
|
||||
nanoseconds_t headerEndTime = 0;
|
||||
nanoseconds_t dataStartTime = 0;
|
||||
nanoseconds_t dataEndTime = 0;
|
||||
int physicalTrack = 0;
|
||||
int physicalSide = 0;
|
||||
int logicalTrack = 0;
|
||||
|
||||
@@ -17,6 +17,9 @@ public:
|
||||
std::unique_ptr<Sector>& get(int track, int head, int sector);
|
||||
Sector* get(int track, int head, int sector) const;
|
||||
|
||||
const std::map<const key_t, std::unique_ptr<Sector>>& get() const
|
||||
{ return _data; }
|
||||
|
||||
void calculateSize(
|
||||
unsigned& numTracks, unsigned& numHeads, unsigned& numSectors,
|
||||
unsigned& sectorSize) const;
|
||||
|
||||
95
lib/visualiser.cc
Normal file
95
lib/visualiser.cc
Normal file
@@ -0,0 +1,95 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#include "globals.h"
|
||||
#include "image.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "visualiser.h"
|
||||
#include "fmt/format.h"
|
||||
#include "flags.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
FlagGroup visualiserFlags;
|
||||
|
||||
static IntFlag period(
|
||||
{ "--visualiser-period" },
|
||||
"rotational period for use by the visualiser (milliseconds)",
|
||||
200);
|
||||
|
||||
static const int SIZE = 480;
|
||||
static const int BORDER = 10;
|
||||
static const int RADIUS = (SIZE/2) - (BORDER/2);
|
||||
static const int CORE = 50;
|
||||
static const int TRACKS = 83;
|
||||
static const double TRACK_SPACING = double(RADIUS-CORE) / TRACKS;
|
||||
|
||||
void visualiseSectorsToFile(const SectorSet& sectors, const std::string& filename)
|
||||
{
|
||||
std::cout << "writing visualisation\n";
|
||||
std::ofstream f(filename, std::ios::out);
|
||||
if (!f.is_open())
|
||||
Error() << "cannot open visualisation file";
|
||||
|
||||
f << fmt::format("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"{0} {1} {2} {3}\">",
|
||||
0, 0, SIZE*2, SIZE);
|
||||
|
||||
const double radians_per_ns = 2.0*M_PI / (period*1e6);
|
||||
|
||||
auto drawSide = [&](int side)
|
||||
{
|
||||
f << fmt::format("<g transform='matrix(1 0 0 -1 {} {})'>", SIZE/2 + (side*SIZE), SIZE/2);
|
||||
f << fmt::format("<circle cx='0' cy='0' r='{}' stroke='none' fill='#ccc'/>", RADIUS);
|
||||
|
||||
for (int physicalTrack = 0; physicalTrack < TRACKS; physicalTrack++)
|
||||
{
|
||||
double radius = CORE + physicalTrack*TRACK_SPACING;
|
||||
f << fmt::format("<circle cx='0' cy='0' r='{}' stroke='#888' stroke-width='0.5' fill='none'/>", radius);
|
||||
|
||||
auto drawArc = [&](const std::unique_ptr<Sector>& sector, nanoseconds_t start, nanoseconds_t end, const std::string& colour)
|
||||
{
|
||||
start %= period*1000000;
|
||||
end %= period*1000000;
|
||||
if (end < start)
|
||||
end += period*1000000;
|
||||
|
||||
double theta1 = start * radians_per_ns;
|
||||
double theta2 = end * radians_per_ns;
|
||||
int large = (theta2 - theta1) >= M_PI;
|
||||
|
||||
f << fmt::format("\n<!-- {} {} = {} {} -->", start, end, theta1, theta2);
|
||||
f << fmt::format("<path fill='none' stroke='{}' stroke-width='1.5' d='", colour);
|
||||
f << fmt::format("M {} {} ", cos(theta1)*radius, sin(theta1)*radius);
|
||||
f << fmt::format("A {0} {0} 0 {3} 1 {1} {2}", radius, cos(theta2)*radius, sin(theta2)*radius, large);
|
||||
f << fmt::format("'><title>Track {} Head {} Sector {}; {}ms to {}ms</title></path>",
|
||||
sector->logicalTrack, sector->logicalSide, sector->logicalSector,
|
||||
start/1e6, end/1e6);
|
||||
};
|
||||
|
||||
/* Sadly, SectorSets aren't indexable by physical track. */
|
||||
for (const auto& e : sectors.get())
|
||||
{
|
||||
const auto& sector = e.second;
|
||||
if ((sector->physicalSide == side) && (sector->physicalTrack == physicalTrack))
|
||||
{
|
||||
const char* colour = "#f00";
|
||||
if (sector->status == Sector::OK)
|
||||
colour = "#00f";
|
||||
if (sector->headerStartTime && sector->headerEndTime)
|
||||
drawArc(sector, sector->headerStartTime, sector->headerEndTime, "#0ff");
|
||||
if (sector->dataStartTime && sector->dataEndTime)
|
||||
drawArc(sector, sector->dataStartTime, sector->dataEndTime, colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f << "</g>";
|
||||
};
|
||||
|
||||
f << fmt::format("<rect x='0' y='0' width='{}' height='{}' stroke='none' fill='#fff'/>", SIZE*2, SIZE);
|
||||
|
||||
drawSide(0);
|
||||
drawSide(1);
|
||||
|
||||
f << "</svg>";
|
||||
}
|
||||
12
lib/visualiser.h
Normal file
12
lib/visualiser.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef VISUALISER_H
|
||||
#define VISUALISER_H
|
||||
|
||||
#include "flags.h"
|
||||
|
||||
class SectorSet;
|
||||
|
||||
extern FlagGroup visualiserFlags;
|
||||
|
||||
extern void visualiseSectorsToFile(const SectorSet& sectors, const std::string& filename);
|
||||
|
||||
#endif
|
||||
@@ -139,6 +139,7 @@ buildlibrary libfmt.a \
|
||||
buildlibrary libbackend.a \
|
||||
lib/imagereader/imagereader.cc \
|
||||
lib/imagereader/imgimagereader.cc \
|
||||
lib/imagewriter/d64imagewriter.cc \
|
||||
lib/imagewriter/imagewriter.cc \
|
||||
lib/imagewriter/imgimagewriter.cc \
|
||||
lib/imagewriter/ldbsimagewriter.cc \
|
||||
@@ -182,12 +183,14 @@ buildlibrary libbackend.a \
|
||||
lib/sectorset.cc \
|
||||
lib/sql.cc \
|
||||
lib/usb.cc \
|
||||
lib/visualiser.cc \
|
||||
lib/writer.cc \
|
||||
|
||||
buildlibrary libfrontend.a \
|
||||
src/fe-cwftoflux.cc \
|
||||
src/fe-erase.cc \
|
||||
src/fe-fluxtoau.cc \
|
||||
src/fe-fluxtoscp.cc \
|
||||
src/fe-fluxtovcd.cc \
|
||||
src/fe-inspect.cc \
|
||||
src/fe-readadfs.cc \
|
||||
@@ -206,6 +209,7 @@ buildlibrary libfrontend.a \
|
||||
src/fe-readvictor9k.cc \
|
||||
src/fe-readzilogmcz.cc \
|
||||
src/fe-rpm.cc \
|
||||
src/fe-scptoflux.cc \
|
||||
src/fe-seek.cc \
|
||||
src/fe-testbulktransport.cc \
|
||||
src/fe-upgradefluxfile.cc \
|
||||
|
||||
188
src/fe-fluxtoscp.cc
Normal file
188
src/fe-fluxtoscp.cc
Normal file
@@ -0,0 +1,188 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "fluxmap.h"
|
||||
#include "sql.h"
|
||||
#include "bytes.h"
|
||||
#include "protocol.h"
|
||||
#include "dataspec.h"
|
||||
#include "fmt/format.h"
|
||||
#include "decoders/fluxmapreader.h"
|
||||
#include "scp.h"
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
static FlagGroup flags { };
|
||||
|
||||
static SettableFlag fortyTrackMode(
|
||||
{ "--48", "-4" },
|
||||
"set 48 tpi mode; only every other physical track is emitted"
|
||||
);
|
||||
|
||||
static SettableFlag singleSided(
|
||||
{ "--single-sided", "-s" },
|
||||
"only emit side 0"
|
||||
);
|
||||
|
||||
static IntFlag diskType(
|
||||
{ "--disk-type" },
|
||||
"sets the SCP disk type byte",
|
||||
0xff
|
||||
);
|
||||
|
||||
static sqlite3* inputDb;
|
||||
|
||||
static void syntax()
|
||||
{
|
||||
std::cout << "Syntax: fluxengine convert fluxtoscp <fluxfile> <scpfile>\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void write_le32(uint8_t dest[4], uint32_t v)
|
||||
{
|
||||
dest[0] = v;
|
||||
dest[1] = v >> 8;
|
||||
dest[2] = v >> 16;
|
||||
dest[3] = v >> 24;
|
||||
}
|
||||
|
||||
static int strackno(int track, int side)
|
||||
{
|
||||
if (fortyTrackMode)
|
||||
track /= 2;
|
||||
if (singleSided)
|
||||
return track;
|
||||
else
|
||||
return (track << 1) | side;
|
||||
}
|
||||
|
||||
int mainConvertFluxToScp(int argc, const char* argv[])
|
||||
{
|
||||
auto filenames = flags.parseFlagsWithFilenames(argc, argv);
|
||||
if (filenames.size() != 2)
|
||||
syntax();
|
||||
|
||||
inputDb = sqlOpen(filenames[0], SQLITE_OPEN_READONLY);
|
||||
auto tracks = sqlFindFlux(inputDb);
|
||||
|
||||
int maxTrack = 0;
|
||||
int maxSide = 0;
|
||||
for (auto p : tracks)
|
||||
{
|
||||
if (singleSided && (p.second == 1))
|
||||
continue;
|
||||
maxTrack = std::max(maxTrack, (int)p.first);
|
||||
maxSide = std::max(maxSide, (int)p.second);
|
||||
}
|
||||
int maxStrack = strackno(maxTrack, maxSide);
|
||||
|
||||
std::cout << fmt::format("Writing {} {} SCP file containing {} SCP tracks\n",
|
||||
fortyTrackMode ? "48 tpi" : "96 tpi",
|
||||
singleSided ? "single sided" : "double sided",
|
||||
maxStrack + 1
|
||||
);
|
||||
|
||||
ScpHeader fileheader = {0};
|
||||
fileheader.file_id[0] = 'S';
|
||||
fileheader.file_id[1] = 'C';
|
||||
fileheader.file_id[2] = 'P';
|
||||
fileheader.file_id[3] = 0x18; /* Version 1.8 of the spec */
|
||||
fileheader.type = diskType;
|
||||
fileheader.revolutions = 5;
|
||||
fileheader.start_track = 0;
|
||||
fileheader.end_track = maxStrack;
|
||||
fileheader.flags = SCP_FLAG_INDEXED | (fortyTrackMode ? 0 : SCP_FLAG_96TPI);
|
||||
fileheader.cell_width = 0;
|
||||
fileheader.heads = singleSided ? 1 : 0;
|
||||
|
||||
Bytes trackdata;
|
||||
ByteWriter trackdataWriter(trackdata);
|
||||
|
||||
int trackstep = 1 + fortyTrackMode;
|
||||
int maxside = singleSided ? 0 : 1;
|
||||
for (int track = 0; track <= maxTrack; track += trackstep)
|
||||
{
|
||||
for (int side = 0; side <= maxside; side++)
|
||||
{
|
||||
int strack = strackno(track, side);
|
||||
std::cout << fmt::format("FE track {}.{}, SCP track {}: ", track, side, strack) << std::flush;
|
||||
|
||||
auto fluxmap = sqlReadFlux(inputDb, track, side);
|
||||
ScpTrack trackheader = {0};
|
||||
trackheader.track_id[0] = 'T';
|
||||
trackheader.track_id[1] = 'R';
|
||||
trackheader.track_id[2] = 'K';
|
||||
trackheader.strack = strack;
|
||||
|
||||
FluxmapReader fmr(*fluxmap);
|
||||
Bytes fluxdata;
|
||||
ByteWriter fluxdataWriter(fluxdata);
|
||||
|
||||
int revolution = 0;
|
||||
unsigned revTicks = 0;
|
||||
unsigned totalTicks = 0;
|
||||
unsigned ticksSinceLastPulse = 0;
|
||||
uint32_t startOffset = 0;
|
||||
while (revolution < 5)
|
||||
{
|
||||
unsigned ticks;
|
||||
int opcode = fmr.readOpcode(ticks);
|
||||
if (ticks)
|
||||
{
|
||||
ticksSinceLastPulse += ticks;
|
||||
totalTicks += ticks;
|
||||
revTicks += ticks;
|
||||
}
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case -1: /* end of flux, treat like an index marker */
|
||||
case F_OP_INDEX:
|
||||
{
|
||||
auto* revheader = &trackheader.revolution[revolution];
|
||||
write_le32(revheader->offset, startOffset + sizeof(ScpTrack));
|
||||
write_le32(revheader->length, (fluxdataWriter.pos - startOffset) / 2);
|
||||
write_le32(revheader->index, revTicks * NS_PER_TICK / 25);
|
||||
revolution++;
|
||||
revheader++;
|
||||
revTicks = 0;
|
||||
startOffset = fluxdataWriter.pos;
|
||||
break;
|
||||
}
|
||||
|
||||
case F_OP_PULSE:
|
||||
{
|
||||
unsigned t = ticksSinceLastPulse * NS_PER_TICK / 25;
|
||||
while (t >= 0x10000)
|
||||
{
|
||||
fluxdataWriter.write_be16(0);
|
||||
t -= 0x10000;
|
||||
}
|
||||
fluxdataWriter.write_be16(t);
|
||||
ticksSinceLastPulse = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write_le32(fileheader.track[strack], trackdataWriter.pos + sizeof(ScpHeader));
|
||||
trackdataWriter += Bytes((uint8_t*)&trackheader, sizeof(trackheader));
|
||||
trackdataWriter += fluxdata;
|
||||
|
||||
std::cout << fmt::format("{} ms in {} bytes\n",
|
||||
totalTicks * MS_PER_TICK,
|
||||
fluxdata.size());
|
||||
}
|
||||
}
|
||||
|
||||
sqlClose(inputDb);
|
||||
|
||||
std::cout << "Writing output file...\n";
|
||||
std::ofstream of(filenames[1], std::ios::out | std::ios::binary);
|
||||
if (!of.is_open())
|
||||
Error() << "cannot open output file";
|
||||
of.write((const char*) &fileheader, sizeof(fileheader));
|
||||
of.write((const char*) trackdata.begin(), trackdata.size());
|
||||
of.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ static FlagGroup flags { &readerFlags };
|
||||
int mainReadC64(int argc, const char* argv[])
|
||||
{
|
||||
setReaderDefaultSource(":t=0-79x2:s=0");
|
||||
setReaderDefaultOutput("c64.img");
|
||||
setReaderDefaultOutput("c64.d64");
|
||||
setReaderRevolutions(2);
|
||||
flags.parseFlags(argc, argv);
|
||||
|
||||
|
||||
@@ -17,13 +17,18 @@ static IntFlag sectorIdBase(
|
||||
"Sector ID of the first sector.",
|
||||
1);
|
||||
|
||||
static BoolFlag ignoreSideByte(
|
||||
{ "--ignore-side-byte" },
|
||||
"Ignore the side byte in the sector ID, and use the physical side instead.",
|
||||
false);
|
||||
|
||||
int mainReadIBM(int argc, const char* argv[])
|
||||
{
|
||||
setReaderDefaultSource(":t=0-79:s=0-1");
|
||||
setReaderDefaultOutput("ibm.img");
|
||||
flags.parseFlags(argc, argv);
|
||||
|
||||
IbmDecoder decoder(sectorIdBase);
|
||||
IbmDecoder decoder(sectorIdBase, ignoreSideByte);
|
||||
readDiskCommand(decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
142
src/fe-scptoflux.cc
Normal file
142
src/fe-scptoflux.cc
Normal file
@@ -0,0 +1,142 @@
|
||||
#include "globals.h"
|
||||
#include "fluxmap.h"
|
||||
#include "sql.h"
|
||||
#include "bytes.h"
|
||||
#include "protocol.h"
|
||||
#include "fmt/format.h"
|
||||
#include "scp.h"
|
||||
#include <fstream>
|
||||
|
||||
static std::ifstream inputFile;
|
||||
static sqlite3* outputDb;
|
||||
static ScpHeader header;
|
||||
static nanoseconds_t resolution;
|
||||
static int startSide;
|
||||
static int endSide;
|
||||
|
||||
static void syntax()
|
||||
{
|
||||
std::cout << "Syntax: fluxengine convert cwftoflux <cwffile> <fluxfile>\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void check_for_error()
|
||||
{
|
||||
if (inputFile.fail())
|
||||
Error() << fmt::format("I/O error: {}", strerror(errno));
|
||||
}
|
||||
|
||||
static int trackno(int strack)
|
||||
{
|
||||
if (startSide == endSide)
|
||||
return strack;
|
||||
return strack >> 1;
|
||||
}
|
||||
|
||||
static int headno(int strack)
|
||||
{
|
||||
if (startSide == endSide)
|
||||
return startSide;
|
||||
return strack & 1;
|
||||
}
|
||||
|
||||
static void read_header()
|
||||
{
|
||||
inputFile.read((char*) &header, sizeof(header));
|
||||
check_for_error();
|
||||
|
||||
if ((header.file_id[0] != 'S')
|
||||
|| (header.file_id[1] != 'C')
|
||||
|| (header.file_id[2] != 'P'))
|
||||
Error() << "input not a SCP file";
|
||||
|
||||
resolution = 25 * (header.resolution + 1);
|
||||
startSide = (header.heads == 2) ? 1 : 0;
|
||||
endSide = (header.heads == 1) ? 0 : 1;
|
||||
|
||||
if ((header.cell_width != 0) && (header.cell_width != 16))
|
||||
Error() << "currently only 16-bit cells are supported";
|
||||
|
||||
std::cout << fmt::format("tracks {}-{}, heads {}-{}\n",
|
||||
trackno(header.start_track), trackno(header.end_track), startSide, endSide);
|
||||
std::cout << fmt::format("sample resolution: {} ns\n", resolution);
|
||||
}
|
||||
|
||||
static void read_track(int strack)
|
||||
{
|
||||
uint32_t offset = Bytes(header.track[strack], 4).reader().read_le32();
|
||||
|
||||
ScpTrack trackheader;
|
||||
inputFile.seekg(offset, std::ios::beg);
|
||||
inputFile.read((char*) &trackheader, sizeof(trackheader));
|
||||
check_for_error();
|
||||
|
||||
if ((trackheader.track_id[0] != 'T')
|
||||
|| (trackheader.track_id[1] != 'R')
|
||||
|| (trackheader.track_id[2] != 'K'))
|
||||
Error() << "corrupt SCP file";
|
||||
|
||||
std::cout << fmt::format("{}.{}: ", trackno(strack), headno(strack))
|
||||
<< std::flush;
|
||||
|
||||
Fluxmap fluxmap;
|
||||
nanoseconds_t pending = 0;
|
||||
unsigned inputBytes = 0;
|
||||
for (int revolution = 0; revolution < header.revolutions; revolution++)
|
||||
{
|
||||
if (revolution != 0)
|
||||
fluxmap.appendIndex();
|
||||
|
||||
uint32_t datalength = Bytes(trackheader.revolution[revolution].length, 4).reader().read_le32();
|
||||
uint32_t dataoffset = Bytes(trackheader.revolution[revolution].offset, 4).reader().read_le32();
|
||||
|
||||
Bytes data(datalength*2);
|
||||
inputFile.seekg(dataoffset + offset, std::ios::beg);
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
check_for_error();
|
||||
|
||||
ByteReader br(data);
|
||||
for (int cell = 0; cell < datalength; cell++)
|
||||
{
|
||||
uint16_t interval = br.read_be16();
|
||||
if (interval)
|
||||
{
|
||||
fluxmap.appendInterval((interval + pending) * resolution / NS_PER_TICK);
|
||||
fluxmap.appendPulse();
|
||||
pending = 0;
|
||||
}
|
||||
else
|
||||
pending += 0x10000;
|
||||
}
|
||||
|
||||
inputBytes += datalength*2;
|
||||
}
|
||||
|
||||
std::cout << fmt::format(" {} ms in {} input bytes and {} output bytes\n",
|
||||
fluxmap.duration() / 1e6, inputBytes, fluxmap.bytes());
|
||||
sqlWriteFlux(outputDb, trackno(strack), headno(strack), fluxmap);
|
||||
}
|
||||
|
||||
int mainConvertScpToFlux(int argc, const char* argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
syntax();
|
||||
|
||||
inputFile.open(argv[1], std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
Error() << fmt::format("cannot open input file '{}'", argv[1]);
|
||||
|
||||
outputDb = sqlOpen(argv[2], SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
||||
sqlPrepareFlux(outputDb);
|
||||
sqlWriteIntProperty(outputDb, "version", FLUX_VERSION_CURRENT);
|
||||
sqlStmt(outputDb, "BEGIN;");
|
||||
|
||||
read_header();
|
||||
inputFile.seekg(sizeof(header), std::ios::beg);
|
||||
for (unsigned i=header.start_track; i<=header.end_track; i++)
|
||||
read_track(i);
|
||||
|
||||
sqlStmt(outputDb, "COMMIT;");
|
||||
sqlClose(outputDb);
|
||||
return 0;
|
||||
}
|
||||
@@ -5,7 +5,9 @@ typedef int command_cb(int agrc, const char* argv[]);
|
||||
extern command_cb mainErase;
|
||||
extern command_cb mainConvertCwfToFlux;
|
||||
extern command_cb mainConvertFluxToAu;
|
||||
extern command_cb mainConvertFluxToScp;
|
||||
extern command_cb mainConvertFluxToVcd;
|
||||
extern command_cb mainConvertScpToFlux;
|
||||
extern command_cb mainInspect;
|
||||
extern command_cb mainReadADFS;
|
||||
extern command_cb mainReadAESLanier;
|
||||
@@ -83,7 +85,9 @@ static std::vector<Command> writeables =
|
||||
static std::vector<Command> convertables =
|
||||
{
|
||||
{ "cwftoflux", mainConvertCwfToFlux, "Converts CatWeasel stream files to flux.", },
|
||||
{ "scptoflux", mainConvertScpToFlux, "Converts Supercard Pro stream files to flux.", },
|
||||
{ "fluxtoau", mainConvertFluxToAu, "Converts (one track of a) flux file to an .au audio file.", },
|
||||
{ "fluxtoscp", mainConvertFluxToScp, "Converrt a flux file to a Supercard Pro file.", },
|
||||
{ "fluxtovcd", mainConvertFluxToVcd, "Converts (one track of a) flux file to a VCD file.", },
|
||||
};
|
||||
|
||||
|
||||
43
src/scp.h
Normal file
43
src/scp.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef SCP_H
|
||||
#define SCP_H
|
||||
|
||||
struct ScpHeader
|
||||
{
|
||||
char file_id[3]; // file ID - 'SCP'
|
||||
uint8_t version; // major/minor in nibbles
|
||||
uint8_t type; // disk type - subclass/class in nibbles
|
||||
uint8_t revolutions; // up to 5
|
||||
uint8_t start_track; // 0..165
|
||||
uint8_t end_track; // 0..165
|
||||
uint8_t flags; // see below
|
||||
uint8_t cell_width; // in bits, 0 meaning 16
|
||||
uint8_t heads; // 0 = both, 1 = side 0 only, 2 = side 1 only
|
||||
uint8_t resolution; // 25ns * (resolution+1)
|
||||
uint8_t checksum[4]; // of data after this point
|
||||
uint8_t track[165][4]; // track offsets, not necessarily 165
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SCP_FLAG_INDEXED = (1<<0),
|
||||
SCP_FLAG_96TPI = (1<<1),
|
||||
SCP_FLAG_360RPM = (1<<2),
|
||||
SCP_FLAG_NORMALIZED = (1<<3),
|
||||
SCP_FLAG_READWRITE = (1<<4),
|
||||
SCP_FLAG_FOOTER = (1<<5)
|
||||
};
|
||||
|
||||
struct ScpTrack
|
||||
{
|
||||
char track_id[3]; // 'TRK'
|
||||
uint8_t strack; // SCP track number
|
||||
struct
|
||||
{
|
||||
uint8_t index[4]; // time for one revolution
|
||||
uint8_t length[4]; // number of bitcells
|
||||
uint8_t offset[4]; // offset to bitcell data, relative to track header
|
||||
}
|
||||
revolution[5];
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user