mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Compare commits
20 Commits
qd
...
FluxEngine
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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>
|
||||
@@ -1058,27 +1065,27 @@
|
||||
<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="DSKCHG" persistent="">
|
||||
<Hidden v="True" />
|
||||
<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="DSKCHG_aliases.h" persistent="Generated_Source\PSoC5\DSKCHG_aliases.h">
|
||||
<Hidden v="True" />
|
||||
<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="DSKCHG.c" persistent="Generated_Source\PSoC5\DSKCHG.c">
|
||||
<Hidden v="True" />
|
||||
<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="DSKCHG.h" persistent="Generated_Source\PSoC5\DSKCHG.h">
|
||||
<Hidden v="True" />
|
||||
<Hidden v="False" />
|
||||
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
|
||||
<build_action v="HEADER;;;;" />
|
||||
<PropertyDeltas />
|
||||
@@ -3284,27 +3291,27 @@
|
||||
</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="READY" persistent="">
|
||||
<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="READY_aliases.h" persistent="Generated_Source\PSoC5\READY_aliases.h">
|
||||
<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="READY.c" persistent="Generated_Source\PSoC5\READY.c">
|
||||
<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="READY.h" persistent="Generated_Source\PSoC5\READY.h">
|
||||
<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;;;;" />
|
||||
@@ -3733,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.
@@ -12,7 +12,7 @@
|
||||
#define STEP_SETTLING_TIME 50 /* ms */
|
||||
|
||||
#define DISKSTATUS_WPT 1
|
||||
#define DISKSTATUS_READY 2 /* Only used on QuickDisk drives */
|
||||
#define DISKSTATUS_DSKCHG 2
|
||||
|
||||
#define STEP_TOWARDS0 1
|
||||
#define STEP_AWAYFROM0 0
|
||||
@@ -37,7 +37,6 @@ static uint8_t dma_channel;
|
||||
static volatile int dma_writing_to_td = 0;
|
||||
static volatile int dma_reading_from_td = 0;
|
||||
static volatile bool dma_underrun = false;
|
||||
static crunch_state_t cs = {};
|
||||
|
||||
#define DECLARE_REPLY_FRAME(STRUCT, TYPE) \
|
||||
STRUCT r = {.f = { .type = TYPE, .size = sizeof(STRUCT) }}
|
||||
@@ -270,8 +269,13 @@ static void init_capture_dma(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void init_capture(void)
|
||||
static void cmd_read(struct read_frame* f)
|
||||
{
|
||||
SIDE_REG_Write(f->side);
|
||||
seek_to(current_track);
|
||||
|
||||
/* Do slow setup *before* we go into the real-time bit. */
|
||||
|
||||
SAMPLER_CONTROL_Write(1); /* reset */
|
||||
|
||||
{
|
||||
@@ -284,103 +288,38 @@ static void init_capture(void)
|
||||
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
init_capture_dma();
|
||||
}
|
||||
|
||||
static void start_capture(void)
|
||||
{
|
||||
memset(&cs, 0, sizeof(crunch_state_t));
|
||||
/* Wait for the beginning of a rotation. */
|
||||
|
||||
print("wait");
|
||||
index_irq = false;
|
||||
while (!index_irq)
|
||||
;
|
||||
index_irq = false;
|
||||
|
||||
crunch_state_t cs = {};
|
||||
cs.outputptr = usb_buffer;
|
||||
cs.outputlen = BUFFER_SIZE;
|
||||
|
||||
dma_writing_to_td = 0;
|
||||
dma_reading_from_td = -1;
|
||||
dma_underrun = false;
|
||||
int count = 0;
|
||||
SAMPLER_CONTROL_Write(0); /* !reset */
|
||||
CAPTURE_CONTROL_Write(1);
|
||||
CyDmaChSetInitialTd(dma_channel, td[dma_writing_to_td]);
|
||||
CyDmaClearPendingDrq(dma_channel);
|
||||
CyDmaChEnable(dma_channel, 1);
|
||||
|
||||
/* Wait for the first DMA transfer to complete, after which we can start
|
||||
* the USB transfer. */
|
||||
/* Wait for the first DMA transfer to complete, after which we can start the
|
||||
* USB transfer. */
|
||||
|
||||
while (dma_writing_to_td == 0)
|
||||
while ((dma_writing_to_td == 0) && !index_irq)
|
||||
;
|
||||
dma_reading_from_td = 0;
|
||||
}
|
||||
|
||||
/* returns true if capture is aborted */
|
||||
static bool do_capture_chunk(void)
|
||||
{
|
||||
/* Wait for the next block to be read. */
|
||||
while (dma_reading_from_td == dma_writing_to_td)
|
||||
{
|
||||
/* On an underrun, give up immediately. */
|
||||
if (dma_underrun)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t dma_buffer_usage = 0;
|
||||
while (dma_buffer_usage < BUFFER_SIZE)
|
||||
{
|
||||
cs.inputptr = dma_buffer[dma_reading_from_td] + dma_buffer_usage;
|
||||
cs.inputlen = BUFFER_SIZE - dma_buffer_usage;
|
||||
crunch(&cs);
|
||||
dma_buffer_usage += BUFFER_SIZE - cs.inputlen;
|
||||
if (cs.outputlen == 0)
|
||||
{
|
||||
while (USBFS_GetEPState(FLUXENGINE_DATA_IN_EP_NUM) != USBFS_IN_BUFFER_EMPTY)
|
||||
{
|
||||
if (dma_underrun)
|
||||
return true;
|
||||
}
|
||||
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, usb_buffer, BUFFER_SIZE);
|
||||
cs.outputptr = usb_buffer;
|
||||
cs.outputlen = BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
dma_reading_from_td = NEXT_BUFFER(dma_reading_from_td);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void stop_capture(void)
|
||||
{
|
||||
CAPTURE_CONTROL_Write(0);
|
||||
CyDmaChSetRequest(dma_channel, CY_DMA_CPU_TERM_CHAIN);
|
||||
while (CyDmaChGetRequest(dma_channel))
|
||||
;
|
||||
|
||||
donecrunch(&cs);
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
if (cs.outputlen != BUFFER_SIZE)
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, usb_buffer, BUFFER_SIZE-cs.outputlen);
|
||||
if ((cs.outputlen == BUFFER_SIZE) || (cs.outputlen == 0))
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, NULL, 0);
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
deinit_dma();
|
||||
}
|
||||
|
||||
static void cmd_read(struct read_frame* f)
|
||||
{
|
||||
SIDE_REG_Write(f->side);
|
||||
seek_to(current_track);
|
||||
|
||||
/* Do slow setup *before* we go into the real-time bit. */
|
||||
|
||||
init_capture();
|
||||
|
||||
/* Wait for the beginning of a rotation. */
|
||||
|
||||
index_irq = false;
|
||||
while (!index_irq)
|
||||
;
|
||||
index_irq = false;
|
||||
|
||||
/* Start transferring. */
|
||||
|
||||
start_capture();
|
||||
int revolutions = f->revolutions;
|
||||
while (!dma_underrun)
|
||||
{
|
||||
@@ -394,77 +333,65 @@ static void cmd_read(struct read_frame* f)
|
||||
if (revolutions == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Wait for the next block to be read. */
|
||||
while (dma_reading_from_td == dma_writing_to_td)
|
||||
{
|
||||
/* On an underrun, give up immediately. */
|
||||
if (dma_underrun)
|
||||
goto abort;
|
||||
}
|
||||
|
||||
if (do_capture_chunk())
|
||||
goto abort;
|
||||
uint8_t dma_buffer_usage = 0;
|
||||
while (dma_buffer_usage < BUFFER_SIZE)
|
||||
{
|
||||
cs.inputptr = dma_buffer[dma_reading_from_td] + dma_buffer_usage;
|
||||
cs.inputlen = BUFFER_SIZE - dma_buffer_usage;
|
||||
crunch(&cs);
|
||||
dma_buffer_usage += BUFFER_SIZE - cs.inputlen;
|
||||
count++;
|
||||
if (cs.outputlen == 0)
|
||||
{
|
||||
while (USBFS_GetEPState(FLUXENGINE_DATA_IN_EP_NUM) != USBFS_IN_BUFFER_EMPTY)
|
||||
{
|
||||
if (index_irq || dma_underrun)
|
||||
goto abort;
|
||||
}
|
||||
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, usb_buffer, BUFFER_SIZE);
|
||||
cs.outputptr = usb_buffer;
|
||||
cs.outputlen = BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
dma_reading_from_td = NEXT_BUFFER(dma_reading_from_td);
|
||||
}
|
||||
abort:;
|
||||
stop_capture();
|
||||
CAPTURE_CONTROL_Write(0);
|
||||
CyDmaChSetRequest(dma_channel, CY_DMA_CPU_TERM_CHAIN);
|
||||
while (CyDmaChGetRequest(dma_channel))
|
||||
;
|
||||
|
||||
donecrunch(&cs);
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
unsigned zz = cs.outputlen;
|
||||
if (cs.outputlen != BUFFER_SIZE)
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, usb_buffer, BUFFER_SIZE-cs.outputlen);
|
||||
if ((cs.outputlen == BUFFER_SIZE) || (cs.outputlen == 0))
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, NULL, 0);
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
deinit_dma();
|
||||
|
||||
if (dma_underrun)
|
||||
{
|
||||
print("underrun after %d packets");
|
||||
send_error(F_ERROR_UNDERRUN);
|
||||
}
|
||||
else
|
||||
{
|
||||
DECLARE_REPLY_FRAME(struct any_frame, F_FRAME_READ_REPLY);
|
||||
send_reply(&r);
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_read_qd(struct read_frame* f)
|
||||
{
|
||||
SIDE_REG_Write(f->side);
|
||||
|
||||
/* Do slow setup *before* we go into the real-time bit. */
|
||||
|
||||
init_capture();
|
||||
|
||||
/* Reset the drive. */
|
||||
|
||||
STEP_REG_Write(2);
|
||||
CyDelay(10); /* ms */
|
||||
STEP_REG_Write(0);
|
||||
|
||||
/* Motor on, and wait for ready. */
|
||||
|
||||
MOTOR_REG_Write(1);
|
||||
while (!(DISKSTATUS_REG_Read() & DISKSTATUS_READY))
|
||||
;
|
||||
|
||||
/* Turning the motor off has no effect until the head hits the stop,
|
||||
* at which point it'll stop automatically. */
|
||||
|
||||
MOTOR_REG_Write(0);
|
||||
|
||||
/* Start transferring. */
|
||||
|
||||
start_capture();
|
||||
while (!dma_underrun)
|
||||
{
|
||||
CyWdtClear();
|
||||
|
||||
/* Have we reached the end? */
|
||||
if (!(DISKSTATUS_REG_Read() & DISKSTATUS_READY))
|
||||
break;
|
||||
|
||||
if (do_capture_chunk())
|
||||
goto abort;
|
||||
}
|
||||
abort:;
|
||||
stop_capture();
|
||||
|
||||
/* Reset the drive again to ensure the motor stops. */
|
||||
|
||||
STEP_REG_Write(2);
|
||||
CyDelay(10); /* ms */
|
||||
STEP_REG_Write(0);
|
||||
|
||||
if (dma_underrun)
|
||||
send_error(F_ERROR_UNDERRUN);
|
||||
else
|
||||
{
|
||||
DECLARE_REPLY_FRAME(struct any_frame, F_FRAME_READ_QD_REPLY);
|
||||
send_reply(&r);
|
||||
}
|
||||
print("count=%d i=%d d=%d zz=%d", count, index_irq, dma_underrun, zz);
|
||||
}
|
||||
|
||||
static void init_replay_dma(void)
|
||||
@@ -720,10 +647,6 @@ static void handle_command(void)
|
||||
cmd_read((struct read_frame*) f);
|
||||
break;
|
||||
|
||||
case F_FRAME_READ_QD_CMD:
|
||||
cmd_read_qd((struct read_frame*) f);
|
||||
break;
|
||||
|
||||
case F_FRAME_WRITE_CMD:
|
||||
cmd_write((struct write_frame*) f);
|
||||
break;
|
||||
|
||||
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
|
||||
-----------------
|
||||
|
||||
45
doc/using.md
45
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,31 @@ directory.
|
||||
file format in a non-backwards-compatible way; this tool will upgrade flux
|
||||
files to the new format.
|
||||
|
||||
- `fluxengine convert`: converts various formats to various other formats.
|
||||
You can use this to convert Catweasel or Supercard Pro flux files to
|
||||
FluxEngine's native format, for flux files to various other formats useful
|
||||
for debugging (including VCD which can be loaded into
|
||||
[sigrok](http://sigrok.org)).
|
||||
|
||||
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 +253,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 |
@@ -112,7 +112,6 @@ FluxSpec::FluxSpec(const DataSpec& spec)
|
||||
|
||||
locations.clear();
|
||||
|
||||
quickdisk = spec.has("qd") && spec.at("qd").only();
|
||||
const auto& drives = spec.at("d").data;
|
||||
if (drives.size() != 1)
|
||||
Error() << "you must specify exactly one drive";
|
||||
@@ -129,7 +128,7 @@ FluxSpec::FluxSpec(const DataSpec& spec)
|
||||
for (const auto& e : spec.modifiers)
|
||||
{
|
||||
const auto name = e.second.name;
|
||||
if ((name != "t") && (name != "s") && (name != "d") && (name != "qd"))
|
||||
if ((name != "t") && (name != "s") && (name != "d"))
|
||||
Error() << fmt::format("unknown fluxspec modifier '{}'", name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ public:
|
||||
std::string filename;
|
||||
std::vector<Location> locations;
|
||||
unsigned drive;
|
||||
bool quickdisk : 1;
|
||||
};
|
||||
|
||||
class ImageSpec
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -15,12 +15,7 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSpec& spec)
|
||||
const auto& filename = spec.filename;
|
||||
|
||||
if (filename.empty())
|
||||
{
|
||||
if (spec.quickdisk)
|
||||
return createQuickdiskFluxSource(spec.drive);
|
||||
else
|
||||
return createHardwareFluxSource(spec.drive);
|
||||
}
|
||||
return createHardwareFluxSource(spec.drive);
|
||||
else if (ends_with(filename, ".flux"))
|
||||
return createSqliteFluxSource(filename);
|
||||
else if (ends_with(filename, "/"))
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "flags.h"
|
||||
|
||||
extern FlagGroup hardwareFluxSourceFlags;
|
||||
extern FlagGroup quickdiskFluxSourceFlags;
|
||||
|
||||
class Fluxmap;
|
||||
class FluxSpec;
|
||||
@@ -17,7 +16,6 @@ public:
|
||||
private:
|
||||
static std::unique_ptr<FluxSource> createSqliteFluxSource(const std::string& filename);
|
||||
static std::unique_ptr<FluxSource> createHardwareFluxSource(unsigned drive);
|
||||
static std::unique_ptr<FluxSource> createQuickdiskFluxSource(unsigned drive);
|
||||
static std::unique_ptr<FluxSource> createStreamFluxSource(const std::string& path);
|
||||
|
||||
public:
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "fluxmap.h"
|
||||
#include "usb.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
|
||||
FlagGroup quickdiskFluxSourceFlags;
|
||||
|
||||
class QuickdiskFluxSource : public FluxSource
|
||||
{
|
||||
public:
|
||||
QuickdiskFluxSource(unsigned drive):
|
||||
_drive(drive)
|
||||
{
|
||||
}
|
||||
|
||||
~QuickdiskFluxSource()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<Fluxmap> readFlux(int track, int side)
|
||||
{
|
||||
usbSetDrive(_drive, false);
|
||||
Bytes crunched = usbReadQD(side);
|
||||
auto fluxmap = std::make_unique<Fluxmap>();
|
||||
fluxmap->appendBytes(crunched.uncrunch());
|
||||
return fluxmap;
|
||||
}
|
||||
|
||||
void recalibrate()
|
||||
{
|
||||
}
|
||||
|
||||
bool retryable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned _drive;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createQuickdiskFluxSource(unsigned drive)
|
||||
{
|
||||
return std::unique_ptr<FluxSource>(new QuickdiskFluxSource(drive));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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, &quickdiskFluxSourceFlags, &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");
|
||||
@@ -85,6 +92,8 @@ std::vector<std::unique_ptr<Track>> readTracks()
|
||||
|
||||
std::cout << "Reading from: " << source << std::endl;
|
||||
|
||||
setHardwareFluxSourceDensity(highDensityFlag);
|
||||
|
||||
if (!destination.get().empty())
|
||||
{
|
||||
outdb = sqlOpen(destination, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
|
||||
@@ -100,9 +109,8 @@ std::vector<std::unique_ptr<Track>> readTracks()
|
||||
);
|
||||
}
|
||||
|
||||
setHardwareFluxSourceDensity(highDensityFlag);
|
||||
|
||||
std::shared_ptr<FluxSource> fluxSource = FluxSource::create(spec);
|
||||
|
||||
std::vector<std::unique_ptr<Track>> tracks;
|
||||
for (const auto& location : spec.locations)
|
||||
{
|
||||
@@ -141,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);
|
||||
@@ -152,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();
|
||||
@@ -250,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;
|
||||
|
||||
21
lib/usb.cc
21
lib/usb.cc
@@ -76,7 +76,7 @@ static void bad_reply(void)
|
||||
{
|
||||
struct error_frame* f = (struct error_frame*) buffer;
|
||||
if (f->f.type != F_FRAME_ERROR)
|
||||
Error() << fmt::format("bad USB reply 0x{:02x}", f->f.type);
|
||||
Error() << fmt::format("bad USB reply 0x{:2x}", f->f.type);
|
||||
switch (f->error)
|
||||
{
|
||||
case F_ERROR_BAD_COMMAND:
|
||||
@@ -221,25 +221,6 @@ Bytes usbRead(int side, int revolutions)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Bytes usbReadQD(int side)
|
||||
{
|
||||
struct read_frame f = {
|
||||
.f = { .type = F_FRAME_READ_QD_CMD, .size = sizeof(f) },
|
||||
.side = (uint8_t) side,
|
||||
.revolutions = 1
|
||||
};
|
||||
usb_cmd_send(&f, f.f.size);
|
||||
|
||||
auto fluxmap = std::unique_ptr<Fluxmap>(new Fluxmap);
|
||||
|
||||
Bytes buffer(1024*1024);
|
||||
int len = large_bulk_transfer(FLUXENGINE_DATA_IN_EP, buffer);
|
||||
buffer.resize(len);
|
||||
|
||||
await_reply<struct any_frame>(F_FRAME_READ_REPLY);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void usbWrite(int side, const Bytes& bytes)
|
||||
{
|
||||
unsigned safelen = bytes.size() & ~(FRAME_SIZE-1);
|
||||
|
||||
@@ -10,7 +10,6 @@ extern void usbSeek(int track);
|
||||
extern nanoseconds_t usbGetRotationalPeriod();
|
||||
extern void usbTestBulkTransport();
|
||||
extern Bytes usbRead(int side, int revolutions);
|
||||
extern Bytes usbReadQD(int side);
|
||||
extern void usbWrite(int side, const Bytes& bytes);
|
||||
extern void usbErase(int side);
|
||||
extern void usbSetDrive(int drive, bool high_density);
|
||||
|
||||
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 \
|
||||
@@ -170,7 +171,6 @@ buildlibrary libbackend.a \
|
||||
lib/fluxsink/sqlitefluxsink.cc \
|
||||
lib/fluxsource/fluxsource.cc \
|
||||
lib/fluxsource/hardwarefluxsource.cc \
|
||||
lib/fluxsource/quickdiskfluxsource.cc \
|
||||
lib/fluxsource/kryoflux.cc \
|
||||
lib/fluxsource/sqlitefluxsource.cc \
|
||||
lib/fluxsource/streamfluxsource.cc \
|
||||
@@ -183,6 +183,7 @@ buildlibrary libbackend.a \
|
||||
lib/sectorset.cc \
|
||||
lib/sql.cc \
|
||||
lib/usb.cc \
|
||||
lib/visualiser.cc \
|
||||
lib/writer.cc \
|
||||
|
||||
buildlibrary libfrontend.a \
|
||||
@@ -204,10 +205,10 @@ buildlibrary libfrontend.a \
|
||||
src/fe-readibm.cc \
|
||||
src/fe-readmac.cc \
|
||||
src/fe-readmx.cc \
|
||||
src/fe-readqd.cc \
|
||||
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 \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
enum
|
||||
{
|
||||
FLUXENGINE_VERSION = 9,
|
||||
FLUXENGINE_VERSION = 8,
|
||||
|
||||
FLUXENGINE_VID = 0x1209,
|
||||
FLUXENGINE_PID = 0x6e00,
|
||||
@@ -54,8 +54,6 @@ enum
|
||||
F_FRAME_BULK_TEST_REPLY, /* any_frame */
|
||||
F_FRAME_READ_CMD, /* read_frame */
|
||||
F_FRAME_READ_REPLY, /* any_frame */
|
||||
F_FRAME_READ_QD_CMD, /* read_frame */
|
||||
F_FRAME_READ_QD_REPLY, /* any_frame */
|
||||
F_FRAME_WRITE_CMD, /* write_frame */
|
||||
F_FRAME_WRITE_REPLY, /* any_frame */
|
||||
F_FRAME_ERASE_CMD, /* erase_frame */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "reader.h"
|
||||
#include "fluxmap.h"
|
||||
#include "decoders/decoders.h"
|
||||
#include "image.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "record.h"
|
||||
#include "ibm/ibm.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
static FlagGroup flags { &readerFlags };
|
||||
|
||||
int mainReadQd(int argc, const char* argv[])
|
||||
{
|
||||
setReaderDefaultSource(":qd=1");
|
||||
setReaderDefaultOutput("qd.img");
|
||||
setReaderRevolutions(2);
|
||||
flags.parseFlags(argc, argv);
|
||||
|
||||
IbmDecoder decoder(0);
|
||||
readDiskCommand(decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
167
src/fe-scptoflux.cc
Normal file
167
src/fe-scptoflux.cc
Normal file
@@ -0,0 +1,167 @@
|
||||
#include "globals.h"
|
||||
#include "fluxmap.h"
|
||||
#include "sql.h"
|
||||
#include "bytes.h"
|
||||
#include "protocol.h"
|
||||
#include "fmt/format.h"
|
||||
#include <fstream>
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
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;
|
||||
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 += interval;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << fmt::format(" {} ms in {} output bytes\n",
|
||||
fluxmap.duration() / 1e6, 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;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ extern command_cb mainErase;
|
||||
extern command_cb mainConvertCwfToFlux;
|
||||
extern command_cb mainConvertFluxToAu;
|
||||
extern command_cb mainConvertFluxToVcd;
|
||||
extern command_cb mainConvertScpToFlux;
|
||||
extern command_cb mainInspect;
|
||||
extern command_cb mainReadADFS;
|
||||
extern command_cb mainReadAESLanier;
|
||||
@@ -20,7 +21,6 @@ extern command_cb mainReadFB100;
|
||||
extern command_cb mainReadIBM;
|
||||
extern command_cb mainReadMac;
|
||||
extern command_cb mainReadMx;
|
||||
extern command_cb mainReadQd;
|
||||
extern command_cb mainReadVictor9K;
|
||||
extern command_cb mainReadZilogMCZ;
|
||||
extern command_cb mainRpm;
|
||||
@@ -72,7 +72,6 @@ static std::vector<Command> readables =
|
||||
{ "ibm", mainReadIBM, "Reads the ubiquitous IBM format disks.", },
|
||||
{ "mac", mainReadMac, "Reads Apple Macintosh disks.", },
|
||||
{ "mx", mainReadMx, "Reads MX disks.", },
|
||||
{ "qd", mainReadQd, "Reads QuickDisk disks.", },
|
||||
{ "victor9k", mainReadVictor9K, "Reads Victor 9000 disks.", },
|
||||
{ "zilogmcz", mainReadZilogMCZ, "Reads Zilog MCZ disks.", },
|
||||
};
|
||||
@@ -85,6 +84,7 @@ 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.", },
|
||||
{ "fluxtovcd", mainConvertFluxToVcd, "Converts (one track of a) flux file to a VCD file.", },
|
||||
};
|
||||
|
||||
@@ -85,15 +85,6 @@ static void test_fluxspec(void)
|
||||
{{1, 9, 1}}));
|
||||
assert((std::string)spec == ":d=1:s=1:t=9");
|
||||
}
|
||||
|
||||
spec.set("");
|
||||
assert(FluxSpec(spec).quickdisk == false);
|
||||
|
||||
spec.set(":qd=0");
|
||||
assert(FluxSpec(spec).quickdisk == false);
|
||||
|
||||
spec.set(":qd=1");
|
||||
assert(FluxSpec(spec).quickdisk == true);
|
||||
}
|
||||
|
||||
static void test_imagespec(void)
|
||||
|
||||
Reference in New Issue
Block a user