1
0
mirror of https://github.com/fruit-bat/pico-zxspectrum.git synced 2025-04-19 00:04:01 +03:00

TZX block 14 - Pure Data

This commit is contained in:
Phil 2022-10-29 21:12:08 +01:00
parent 2d5566d65a
commit a5f9d99d0e
6 changed files with 133 additions and 4 deletions

View File

@ -29,7 +29,9 @@ set(zxspectrum_common_src
${CMAKE_CURRENT_LIST_DIR}/PulseProcTzxPureTone.cpp
${CMAKE_CURRENT_LIST_DIR}/PulseProcPulseStream.cpp
${CMAKE_CURRENT_LIST_DIR}/PulseProcTzxPulseSequence.cpp
${CMAKE_CURRENT_LIST_DIR}/PulseProcTzxPureData.cpp
${CMAKE_CURRENT_LIST_DIR}/ZxSpectrumFile.cpp
${CMAKE_CURRENT_LIST_DIR}/ZxSpectrumFileLoop.cpp
${CMAKE_CURRENT_LIST_DIR}/ZxSpectrumFatFsSpiFileLoop.cpp

View File

@ -20,7 +20,7 @@ void __not_in_flash_func(PulseProcStdByte::init)(
uint32_t ts1
) {
next(nxt);
_b = b | (1 << (16 - n));
_b = b | (1 << (16 - (n > 8 ? 8 : n)));
_ts[0] = ts0;
_ts[1] = ts1;
}

View File

@ -15,6 +15,7 @@ PulseProcTzxBlock::PulseProcTzxBlock(
_ppTzxPureTone(ppTone1),
_ppPulseStream(ppTone1),
_ppTzxPulseSequence(&_ppPulseStream),
_ppTzxPureData(data, ppTone2, pause),
_tsPerMs(3555)
{}
@ -105,8 +106,9 @@ int32_t PulseProcTzxBlock::doSequence(InputStream *is, PulseProc **top) {
* 0x0A - BYTE[N] Data as in .TAP files
*/
int32_t PulseProcTzxBlock::doPureData(InputStream *is, PulseProc **top) {
const int8_t l[] = {-0x7, 3};
return skipSingle(is, l, 2, 1);
_ppTzxPureData.init(this, _tsPerMs);
*top = _ppTap;
return PP_CONTINUE;
}
/** ID 15 - Direct Recording

View File

@ -8,6 +8,7 @@
#include "PulseProcTzxPureTone.h"
#include "PulseProcPulseStream.h"
#include "PulseProcTzxPulseSequence.h"
#include "PulseProcTzxPureData.h"
class PulseProcTzxBlock : public PulseProc {
private:
@ -18,6 +19,7 @@ private:
PulseProcTzxPureTone _ppTzxPureTone;
PulseProcPulseStream _ppPulseStream;
PulseProcTzxPulseSequence _ppTzxPulseSequence;
PulseProcTzxPureData _ppTzxPureData;
uint32_t _tsPerMs;
int32_t doBlock(InputStream *is, int32_t bt, PulseProc **top);

View File

@ -0,0 +1,86 @@
#include "PulseProcTzxPureData.h"
PulseProcTzxPureData::PulseProcTzxPureData(
PulseProcStdByteStream* data,
PulseProcTone* end,
PulseProcPauseMillis* pause
) :
_data(data),
_end(end),
_pause(pause)
{
}
void PulseProcTzxPureData::init(
PulseProc *nxt,
uint32_t tsPerMs
) {
next(nxt);
_tsPerMs = tsPerMs;
}
/**
* ID 14 - Pure Data Block
*
* length: [07,08,09]+0A
*
* Offset Value Type Description
* 0x00 - WORD Length of ZERO bit pulse
* 0x02 - WORD Length of ONE bit pulse
* 0x04 - BYTE Used bits in last byte (other bits should be 0)
* (e.g. if this is 6, then the bits used (x) in the last byte are: xxxxxx00, where MSb is the leftmost bit, LSb is the rightmost bit)
* 0x05 - WORD Pause after this block (ms.)
* 0x07 N BYTE[3] Length of data that follow
* 0x0A - BYTE[N] Data as in .TAP files
*/
int32_t __not_in_flash_func(PulseProcTzxPureData::advance)(
InputStream *is,
bool *pstate,
PulseProc **top
) {
DBG_PULSE("PulseProcTzxPureData: \n");
const int8_t l[] = {
2, // 0. WORD Length of ZERO bit pulse {855}
2, // 1. WORD Length of ONE bit pulse {1710}
1, // 2. BYTE Used bits in the last byte (other bits should be 0) {8}
2, // 3. WORD Pause after this block (ms.) {1000}
3 // 4. BYTE[3] Length of data that follow
};
uint32_t h[5];
int32_t r = is->decodeLsbf(h, l, 5);
if (r < 0) {
DBG_PULSE("PulseProcTzxPureData: Error (%ld) reading pure data header\n", r);
return PP_ERROR;
}
else {
DBG_PULSE("PulseProcTzxPureData: Length of ZERO bit pulse %ld\n", h[0]);
DBG_PULSE("PulseProcTzxPureData: Length of ONE bit pulse %ld\n", h[1]);
DBG_PULSE("PulseProcTzxPureData: Used bits in the last byte %ld\n", h[2]);
DBG_PULSE("PulseProcTzxPureData: Pause after this block %ld\n", h[3]);
DBG_PULSE("PulseProcTzxPureData: Length of data that follow %ld\n", h[4]);
_data->init(
_end,
h[4], // 4. BYTE[3] Length of data that follow
h[0], // 0. WORD Length of ZERO bit pulse {855}
h[4], // 4. WORD Length of ONE bit pulse {1710}
h[2] // 2. BYTE Used bits in the last byte
);
_end->init(_pause, 0, 1);
_pause->init(
next(),
h[3], // 3. WORD Pause after this block (ms.) {1000}
_tsPerMs
);
*top = _data;
return PP_CONTINUE;
}
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <pico/stdlib.h>
#include "PulseProc.h"
#include "PulseProcTone.h"
#include "PulseProcStdHeader.h"
#include "PulseProcStdByteStream.h"
#include "PulseProcStdByte.h"
#include "PulseProcPauseMillis.h"
class PulseProcTzxPureData : public PulseProc {
private:
PulseProcStdByteStream* _data;
PulseProcTone* _end;
PulseProcPauseMillis* _pause;
uint32_t _tsPerMs;
public:
PulseProcTzxPureData(
PulseProcStdByteStream* data,
PulseProcTone* end,
PulseProcPauseMillis* pause
);
void init(
PulseProc *nxt,
uint32_t tsPerMs
);
virtual int32_t __not_in_flash_func(advance)(
InputStream *is,
bool *pstate,
PulseProc **top
);
};