This commit is contained in:
iceman1001 2022-01-06 23:25:25 +01:00
commit 81c6918ac5
5 changed files with 27 additions and 19 deletions

View file

@ -93,41 +93,49 @@ static inline void clear_bitarray24(uint32_t *bitarray) {
memset(bitarray, 0x00, sizeof(uint32_t) * (1 << 19)); memset(bitarray, 0x00, sizeof(uint32_t) * (1 << 19));
} }
static inline uint32_t test_bit24(const uint32_t *bitarray, uint32_t index) {
static inline uint32_t test_bit24(uint32_t *bitarray, uint32_t index) {
return bitarray[index >> 5] & (0x80000000 >> (index & 0x0000001f)); return bitarray[index >> 5] & (0x80000000 >> (index & 0x0000001f));
} }
static inline void set_bit24(uint32_t *bitarray, uint32_t index) { static inline void set_bit24(uint32_t *bitarray, uint32_t index) {
bitarray[index >> 5] |= 0x80000000 >> (index & 0x0000001f); bitarray[index >> 5] |= 0x80000000 >> (index & 0x0000001f);
} }
static inline uint32_t next_state(const uint32_t *bitset, uint32_t state) {
if (++state == 1 << 24) {
return 1 << 24;
}
static inline uint32_t next_state(uint32_t *bitset, uint32_t state) {
if (++state == 1 << 24) return 1 << 24;
uint32_t index = state >> 5; uint32_t index = state >> 5;
uint_fast8_t bit = state & 0x1f; uint_fast8_t bit = state & 0x1f;
uint32_t line = bitset[index] << bit; uint32_t line = bitset[index] << bit;
while (bit <= 0x1f) { while (bit <= 0x1f) {
if (line & 0x80000000) return state; if (line & 0x80000000) {
return state;
}
state++; state++;
bit++; bit++;
line <<= 1; line <<= 1;
} }
index++; index++;
while (bitset[index] == 0x00000000 && state < 1 << 24) { while (bitset[index] == 0x00000000 && state < 1 << 24) {
index++; index++;
state += 0x20; state += 0x20;
} }
if (state >= 1 << 24) return 1 << 24;
if (state >= 1 << 24) {
return 1 << 24;
}
#if defined __GNUC__ #if defined __GNUC__
return state + __builtin_clz(bitset[index]); return state + __builtin_clz(bitset[index]);
#else #else
bit = 0x00; bit = 0x00;
line = bitset[index]; line = bitset[index];
while (bit <= 0x1f) { while (bit <= 0x1f) {
if (line & 0x80000000) return state; if (line & 0x80000000) {
return state;
}
state++; state++;
bit++; bit++;
line <<= 1; line <<= 1;
@ -137,7 +145,7 @@ static inline uint32_t next_state(uint32_t *bitset, uint32_t state) {
} }
static inline uint32_t next_not_state(uint32_t *bitset, uint32_t state) { static inline uint32_t next_not_state(const uint32_t *bitset, uint32_t state) {
if (++state == 1 << 24) return 1 << 24; if (++state == 1 << 24) return 1 << 24;
uint32_t index = state >> 5; uint32_t index = state >> 5;
uint_fast8_t bit = state & 0x1f; uint_fast8_t bit = state & 0x1f;

View file

@ -686,7 +686,7 @@ int saveFileJSONrootEx(const char *preferredName, void *root, size_t flags, bool
return PM3_EFILE; return PM3_EFILE;
} }
int saveFileWAVE(const char *preferredName, int *data, size_t datalen) { int saveFileWAVE(const char *preferredName, const int *data, size_t datalen) {
if (data == NULL) return PM3_EINVARG; if (data == NULL) return PM3_EINVARG;
char *fileName = newfilenamemcopy(preferredName, ".wav"); char *fileName = newfilenamemcopy(preferredName, ".wav");

View file

@ -127,7 +127,7 @@ int saveFileJSONrootEx(const char *preferredName, void *root, size_t flags, bool
* @param datalen the length of the data * @param datalen the length of the data
* @return 0 for ok * @return 0 for ok
*/ */
int saveFileWAVE(const char *preferredName, int *data, size_t datalen); int saveFileWAVE(const char *preferredName, const int *data, size_t datalen);
/** STUB /** STUB
* @brief Utility function to save PM3 data to a file. This method takes a preferred name, but if that * @brief Utility function to save PM3 data to a file. This method takes a preferred name, but if that

View file

@ -72,8 +72,8 @@ void save_restoreGB(uint8_t saveOpt) {
} }
} }
void setGraphBuf(uint8_t *buff, size_t size) { void setGraphBuf(const uint8_t *src, size_t size) {
if (buff == NULL) return; if (src == NULL) return;
ClearGraph(false); ClearGraph(false);
@ -81,14 +81,14 @@ void setGraphBuf(uint8_t *buff, size_t size) {
size = MAX_GRAPH_TRACE_LEN; size = MAX_GRAPH_TRACE_LEN;
for (size_t i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
g_GraphBuffer[i] = buff[i] - 128; g_GraphBuffer[i] = src[i] - 128;
g_GraphTraceLen = size; g_GraphTraceLen = size;
RepaintGraphWindow(); RepaintGraphWindow();
} }
size_t getFromGraphBuf(uint8_t *buff) { size_t getFromGraphBuf(uint8_t *dest) {
if (buff == NULL) return 0; if (dest == NULL) return 0;
if (g_GraphTraceLen == 0) return 0; if (g_GraphTraceLen == 0) return 0;
size_t i; size_t i;
@ -96,7 +96,7 @@ size_t getFromGraphBuf(uint8_t *buff) {
//trim //trim
if (g_GraphBuffer[i] > 127) g_GraphBuffer[i] = 127; if (g_GraphBuffer[i] > 127) g_GraphBuffer[i] = 127;
if (g_GraphBuffer[i] < -127) g_GraphBuffer[i] = -127; if (g_GraphBuffer[i] < -127) g_GraphBuffer[i] = -127;
buff[i] = (uint8_t)(g_GraphBuffer[i] + 128); dest[i] = (uint8_t)(g_GraphBuffer[i] + 128);
} }
return i; return i;
} }

View file

@ -20,9 +20,9 @@ extern "C" {
void AppendGraph(bool redraw, uint16_t clock, int bit); void AppendGraph(bool redraw, uint16_t clock, int bit);
size_t ClearGraph(bool redraw); size_t ClearGraph(bool redraw);
bool HasGraphData(void); bool HasGraphData(void);
void setGraphBuf(uint8_t *buff, size_t size); void setGraphBuf(const uint8_t *src, size_t size);
void save_restoreGB(uint8_t saveOpt); void save_restoreGB(uint8_t saveOpt);
size_t getFromGraphBuf(uint8_t *buff); size_t getFromGraphBuf(uint8_t *dest);
void convertGraphFromBitstream(void); void convertGraphFromBitstream(void);
void convertGraphFromBitstreamEx(int hi, int low); void convertGraphFromBitstreamEx(int hi, int low);
bool isGraphBitstream(void); bool isGraphBitstream(void);