- [CHG] zx_screen pinta t_state a t_state, per a que es vegen les ralles al carregar

- [FIX] Ja carrega blocs capçalera i blocs programa. Falla el següent...
This commit is contained in:
2024-04-21 21:53:34 +02:00
parent ddcb40b289
commit 9b603604e9
5 changed files with 144 additions and 60 deletions

View File

@@ -28,9 +28,7 @@ namespace zx_tape
struct block_t
{
uint16_t length;
uint8_t flag;
uint8_t *data;
uint8_t checksum;
};
bool playing = false;
@@ -56,11 +54,11 @@ namespace zx_tape
{
block_t block;
fread(&block.length, 2, 1, f);
fread(&block.flag, 1, 1, f);
block.length -= 2; // substract flag and checksum
//fread(&block.flag, 1, 1, f);
//block.length -= 2; // substract flag and checksum
block.data = (uint8_t *)malloc(block.length);
fread(block.data, block.length, 1, f);
fread(&block.checksum, 1, 1, f);
//fread(&block.checksum, 1, 1, f);
blocks.push_back(block);
}
fclose(f);
@@ -73,7 +71,7 @@ namespace zx_tape
void play()
{
if (!loaded) return;
playing = true;
playing = !playing; //true;
}
void stop()
@@ -98,13 +96,17 @@ namespace zx_tape
if (current_section == PULSE_PILOT)
{
const uint16_t pulse_count = blocks[current_block].flag<128 ? PULSE_COUNT_PILOT_HEADER : PULSE_COUNT_PILOT_DATA;
const uint16_t pulse_count = blocks[current_block].data[0]<128 ? PULSE_COUNT_PILOT_HEADER : PULSE_COUNT_PILOT_DATA;
if (pulse_pos >= PULSE_LEN_PILOT )
{
pulse_pos -= PULSE_LEN_PILOT;
current_pulse++;
pulse_level = pulse_level?0:1;
if (current_pulse >= pulse_count)
if (current_pulse == pulse_count && pulse_level==0)
{
pulse_level = 0;
}
else if (current_pulse >= pulse_count)
{
current_pulse = 0;
pulse_level = 1;
@@ -132,18 +134,21 @@ namespace zx_tape
current_section = PULSE_DATA;
}
}
static int level[2] = {0, 0};
if (current_section == PULSE_DATA)
{
level[pulse_level]+=dt;
const uint8_t datum = blocks[current_block].data[block_pos];
const uint16_t pulse_len = (datum & (0x80>>current_bit)) == 0 ? PULSE_LEN_ZERO : PULSE_LEN_ONE;
if (pulse_pos >= pulse_len)
{
pulse_pos -= pulse_len;
pulse_pos =0;//-= pulse_len;
pulse_level--;
if (pulse_level>=2)
{
pulse_level = 1;
//printf("%i\n",current_bit);
level[0]=level[1]=0;
current_bit++;
if (current_bit>=8)
{
@@ -152,16 +157,16 @@ namespace zx_tape
if (block_pos>=blocks[current_block].length)
{
block_pos = 0;
current_section = PULSE_CHECKSUM;
current_section = PULSE_SYNC3;
}
}
}
}
}
if (current_section == PULSE_CHECKSUM)
/*if (current_section == PULSE_CHECKSUM)
{
const uint8_t datum = blocks[current_block].checksum;
const uint8_t datum = 1;//blocks[current_block].checksum;
const uint16_t pulse_len = (datum & (0x80>>current_bit)) == 0 ? PULSE_LEN_ZERO : PULSE_LEN_ONE;
if (pulse_pos >= pulse_len)
{
@@ -178,7 +183,7 @@ namespace zx_tape
}
}
}
}
}*/
if (current_section == PULSE_SYNC3)
{
@@ -196,6 +201,7 @@ namespace zx_tape
pulse_level = 0;
if (pulse_pos >= 3500000)
{
pulse_pos = 0;
current_section = PULSE_PILOT;
pulse_level = 1;
current_block++;