"sck=" property support.

This commit is contained in:
Jean-François DEL NERO
2025-04-04 21:57:31 +02:00
parent 8c039ee314
commit c75f19c290
2 changed files with 110 additions and 72 deletions
@@ -58,20 +58,12 @@
#include "kryofluxstream_loader.h"
#include "kryofluxstream_format.h"
#include "kryofluxstream.h"
#include "libhxcadaptor.h"
/*
#define KF_MCLOCK 48054857,14 //(((18432000 * 73) / 14) / 2)
#define KF_SCLOCK ((float)KF_MCLOCK / (float)2)
#define KF_ICLOCK (KF_MCLOCK / 16)
*/
#define KF_NS_PER_TICK 41619 // 41,619 ns per tick
#define MAX_INDEX 128
//#define KFSTREAMDBG 1
#include "libhxcadaptor.h"
#define MAX_INDEX 128
//#define KFSTREAMDBG 1
typedef struct Index_
{
@@ -111,15 +103,16 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
HXCFE_TRKSTREAM * track_dump;
Index index_events[MAX_INDEX];
FILE* f;
#ifdef KFSTREAMDBG
char * tempstr;
s_oob_StreamRead * streamRead;
s_oob_StreamEnd * streamEnd;
FILE* f;
char * tempstr;
#ifdef KFSTREAMDBG
s_oob_StreamRead * streamRead;
s_oob_StreamEnd * streamEnd;
#endif
unsigned char * kfstreambuffer;
@@ -145,12 +138,19 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
uint8_t cur_op,cur_op_len;
int new_cell_available;
track_dump = NULL;
kfstreambuffer = NULL;
if(fxs)
{
f = hxc_fopen(file,"rb");
track_dump = NULL;
kfstreambuffer = NULL;
double sck;
double sampleperiod;
char *sck_strpos;
sck = DEFAULT_KF_SCLOCK;
sampleperiod = (1E9/sck) * 1000.0; // default 41.619 ns
if(fxs)
{
f = hxc_fopen(file,"rb");
if(f)
{
filesize = hxc_fgetsize(f);
@@ -359,24 +359,59 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
break;
case OOBTYPE_String:
#ifdef KFSTREAMDBG
floppycontext->hxc_printf(MSG_DEBUG,"---String---");
#endif
#ifdef KFSTREAMDBG
tempstr = malloc(oob->Size+1);
if( tempstr )
{
memset(tempstr,0,oob->Size+1);
memcpy(tempstr,&kfstreambuffer[stream_ofs + sizeof(s_oob_header)],oob->Size);
#ifdef KFSTREAMDBG
floppycontext->hxc_printf(MSG_DEBUG,"---String---");
#endif
tempstr = malloc(oob->Size+1);
if( tempstr )
{
memset(tempstr,0,oob->Size+1);
memcpy(tempstr,&kfstreambuffer[stream_ofs + sizeof(s_oob_header)],oob->Size);
#ifdef KFSTREAMDBG
floppycontext->hxc_printf(MSG_DEBUG,"String : %s",tempstr);
#endif
sck_strpos = strstr(tempstr, "sck=");
if( sck_strpos )
{
char tmpstrfreq[64];
int str_i;
sck_strpos += strlen("sck=");
str_i = 0;
while( *sck_strpos != 0 && *sck_strpos != ',' && str_i<(sizeof(tmpstrfreq) - 1))
{
if( (*sck_strpos >= '0' && *sck_strpos <= '9') || *sck_strpos == '.' )
{
tmpstrfreq[str_i++] = *sck_strpos;
}
sck_strpos++;
}
tmpstrfreq[str_i++] = 0;
sck = atof(tmpstrfreq);
floppycontext->hxc_printf(MSG_DEBUG,"String : %s",tempstr);
free(tempstr);
tempstr = NULL;
}
#endif
break;
case OOBTYPE_End:
floppycontext->hxc_printf(MSG_DEBUG,"sck: %.16f",sck);
if( sck >= (4 * 1000000) && sck <= (250 * 1000000) )
{
// ns per tick
sampleperiod = (1E9/sck) * 1000.0;
floppycontext->hxc_printf(MSG_DEBUG,"sampleperiod: %.16f",sampleperiod);
}
else
{
floppycontext->hxc_printf(MSG_ERROR,"sck is out of range! (%.16f)",sck);
sck = DEFAULT_KF_SCLOCK;
sampleperiod = (1E9/sck) * 1000.0;
}
}
free(tempstr);
tempstr = NULL;
}
break;
case OOBTYPE_End:
oobEnd = 1;
break;
@@ -450,13 +485,13 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
}
}
}
}
}
hxcfe_FxStream_setResolution(fxs,KF_NS_PER_TICK);
track_dump = hxcfe_FxStream_ImportStream(fxs,cellstream,32,cellpos, HXCFE_STREAMCHANNEL_TYPE_RLEEVT, "data",NULL);
}
}
hxcfe_FxStream_setResolution(fxs,(int)sampleperiod);
track_dump = hxcfe_FxStream_ImportStream(fxs,cellstream,32,cellpos, HXCFE_STREAMCHANNEL_TYPE_RLEEVT, "data",NULL);
for(i=0;i<nbindex;i++)
{
index_events[i].type = FXSTRM_INDEX_MAININDEX;
@@ -501,13 +536,13 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
{
Next_Max_Index_Tick = index_events[i].Next_Index_Tick;
}
}
// Max index delta is < to 50 ms, load this track as an hard sectored track.
if ( (Next_Max_Index_Tick * ((float)KF_NS_PER_TICK * 10E-10)) < 50 && (Prev_Max_Index_Tick * ((float)KF_NS_PER_TICK * 10E-10)) < 50 )
{
for( i = 0; i < nbindex ; i++ )
{
}
// Max index delta is < to 50 ms, load this track as an hard sectored track.
if ( (Next_Max_Index_Tick * (sampleperiod * 10E-10)) < 50 && (Prev_Max_Index_Tick * (sampleperiod * 10E-10)) < 50 )
{
for( i = 0; i < nbindex ; i++ )
{
if ( ( index_events[i].Prev_Index_Tick > ( Prev_Max_Index_Tick / 4 ) * 3 ) &&
( index_events[i].Next_Index_Tick > ( Next_Max_Index_Tick / 4 ) * 3 ) )
{
@@ -567,14 +602,14 @@ HXCFE_TRKSTREAM* DecodeKFStreamFile(HXCFE* floppycontext,HXCFE_FXSA * fxs,char *
}
}
for( i = 0; i < nbindex ; i++ )
{
floppycontext->hxc_printf(MSG_DEBUG,"Index %d : Prev delta %f ms, Next delta %f ms, Type : 0x%x",i, \
(float)index_events[i].Prev_Index_Tick * ((float)KF_NS_PER_TICK * 10E-10), \
(float)index_events[i].Next_Index_Tick * ((float)KF_NS_PER_TICK * 10E-10), \
index_events[i].type);
hxcfe_FxStream_AddIndex(fxs,track_dump,index_events[i].CellPos,index_events[i].Timer,index_events[i].type);
for( i = 0; i < nbindex ; i++ )
{
floppycontext->hxc_printf(MSG_DEBUG,"Index %d : Prev delta %f ms, Next delta %f ms, Type : 0x%x",i, \
(float)index_events[i].Prev_Index_Tick * (sampleperiod * 10E-10), \
(float)index_events[i].Next_Index_Tick * (sampleperiod * 10E-10), \
index_events[i].type);
hxcfe_FxStream_AddIndex(fxs,track_dump,index_events[i].CellPos,index_events[i].Timer,index_events[i].type);
}
}
@@ -63,7 +63,10 @@ typedef struct s_oob_DiskIndex_
#define OOBTYPE_Stream_Read 0x01 // Start of flux transition timing data block (multiple per track)
#define OOBTYPE_Index 0x02 // Index Index signal data
#define OOBTYPE_Stream_End 0x03 // Stream End Signifies there are no more stream read blocks (one per track)
#define OOBTYPE_String 0x04 // String info
#define OOBTYPE_End 0x0D // End of data (no more data to process)
#pragma pack()
#define OOBTYPE_String 0x04 // String info
#define OOBTYPE_End 0x0D // End of data (no more data to process)
#define DEFAULT_KF_MCLOCK (double)48054857.14285714 // (((18432000 * 73) / 14) / 2)
#define DEFAULT_KF_SCLOCK (double)(DEFAULT_KF_MCLOCK / 2) // Default 41.619 ns per tick
#pragma pack()