Disk read optimization

This commit is contained in:
tudnai 2020-06-11 14:50:07 -07:00
parent fad4956135
commit 25d4ca31fd
3 changed files with 148 additions and 15 deletions

Binary file not shown.

View File

@ -44,6 +44,29 @@ const int position_to_direction[8][8] = {
};
const uint8_t phy2log_dos33[16] = {
0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15
};
const uint8_t log2phy_dos33[16] = {
0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15
};
const uint8_t phy2log_pascal[16] = {
0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15
};
const uint8_t log2phy_pascal[16] = {
0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15
};
const uint8_t phy2log_cpm[16] = {
0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5
};
const uint8_t log2phy_cpm[16] = {
0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13
};
void disk_accelerator_speedup() {
if ( diskAccelerator_speed >= clk_6502_per_frm ) {
clk_6502_per_frm =
@ -101,6 +124,9 @@ uint8_t disk_read() {
disk.clk_last_access = m6502.clktime;
disk_accelerator_speedup();
// Debug disk read
// spkr_toggle();
return woz_read();
}

View File

@ -368,6 +368,95 @@ uint8_t woz_read() {
printf("READ: clk:%llu to:%u bo:%llu B:%02X\n", m6502.clktime, trackOffset, (m6502.clktime >> 2) & 7, readLatch);
return readLatch;
#elif defined( WOZ_SEARCH_NEXTSECT )
static int clkBeforeSync = 0;
clkelpased = m6502.clktime + clkfrm - m6502.clklast;
m6502.clklast = m6502.clktime + clkfrm;
clkBeforeSync += clkelpased;
const int clkBeforeAdjusting = 1024;
const int magicShiftOffset = 8192;
uint16_t usedBytes = woz_trks[track].bytes_used < WOZ_TRACK_BYTE_COUNT ? woz_trks[track].bytes_used : WOZ_TRACK_BYTE_COUNT;
if ( usedBytes ) {
// printf("elpased : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync);
if ( clkelpased > clkBeforeAdjusting ) {
// printf("NEED SYNC : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync);
clkBeforeSync = 0;
// bitOffset = (clkelpased >> 2) & 7;
// bitOffset = 0;
// trackOffset += clkelpased >> 5;
// trackOffset %= usedBytes;
// preroll data stream
// WOZread.shift16 = 0;
// WOZread.data = woz_trks[track].data[trackOffset++];
// trackOffset %= usedBytes;
// WOZread.shift16 <<= bitOffset;
int w = 2; // 2 x 0xD5
for ( int i = 0; i < usedBytes * 8; i++ ) {
if ( ++bitOffset >= 8 ) {
bitOffset = 0;
trackOffset++;
trackOffset %= usedBytes;
WOZread.data = woz_trks[track].data[trackOffset];
}
WOZread.shift16 <<= 1;
if ( WOZread.valid ) {
uint8_t byte = WOZread.shift;
WOZread.shift = 0;
// find next sector or end of sector
if ( byte == 0xD5 ) {
// actually 2 sectors, because of DOS 3.3 interleaving algoritm
if ( --w <= 0 ) {
return byte;
}
}
}
}
}
// to avoid infinite loop and to search for bit 7 high
for ( int i = 0; i < usedBytes * 8; i++ ) {
if ( ++bitOffset >= 8 ) {
bitOffset = 0;
// if ( ++trackOffset >= WOZ_TRACK_BYTE_COUNT ) {
// trackOffset = 0;
// }
trackOffset++;
trackOffset %= usedBytes;
// printf("offs:%u\n", trackOffset);
WOZread.data = woz_trks[track].data[trackOffset];
}
WOZread.shift16 <<= 1;
if ( WOZread.valid ) {
uint8_t byte = WOZread.shift;
// printf("%02X ", byte);
WOZread.shift = 0;
if (outdev) fprintf(outdev, "byte: %02X\n", byte);
return byte;
}
}
if (outdev) fprintf(outdev, "TIME OUT!\n");
}
return rand();
#else // WOZ_REAL_SPIN
static int clkBeforeSync = 0;
@ -383,6 +472,8 @@ uint8_t woz_read() {
uint16_t usedBytes = woz_trks[track].bytes_used < WOZ_TRACK_BYTE_COUNT ? woz_trks[track].bytes_used : WOZ_TRACK_BYTE_COUNT;
if ( usedBytes ) {
// printf("elpased : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync);
if ( clkelpased > clkBeforeAdjusting ) {
// printf("NEED SYNC : %llu (clkBefRd:%d)\n", clkelpased, clkBeforeSync);
clkBeforeSync = 0;
@ -394,13 +485,13 @@ uint8_t woz_read() {
WOZread.shift16 = 0;
WOZread.data = woz_trks[track].data[trackOffset++];
trackOffset %= usedBytes;
WOZread.shift16 <<= bitOffset;
for ( int i = 0; i < magicShiftOffset; i++ ) {
for ( ; bitOffset < 8; bitOffset++ ) {
WOZread.shift16 <<= 1;
if ( WOZread.valid ) {
WOZread.shift = 0;
}
@ -410,32 +501,48 @@ uint8_t woz_read() {
bitOffset = 0;
}
}
else {
uint64_t bitForward = (clkelpased >> 2);
// to avoid infinite loop and to search for bit 7 high
for ( uint64_t i = 0; i < bitForward; i++ ) {
if ( ++bitOffset >= 8 ) {
bitOffset = 0;
trackOffset++;
trackOffset %= usedBytes;
WOZread.data = woz_trks[track].data[trackOffset];
}
WOZread.shift16 <<= 1;
if ( WOZread.valid ) {
WOZread.shift = 0;
}
}
}
// to avoid infinite loop and to search for bit 7 high
for ( int i = 0; i < usedBytes * 8; i++ ) {
if ( WOZread.valid ) {
uint8_t byte = WOZread.shift;
WOZread.shift = 0;
// if (outdev) fprintf(outdev, "byte: %02X\n", byte);
return byte;
}
if ( ++bitOffset >= 8 ) {
bitOffset = 0;
// if ( ++trackOffset >= WOZ_TRACK_BYTE_COUNT ) {
// trackOffset = 0;
// }
trackOffset++;
trackOffset %= usedBytes;
// printf("offs:%u\n", trackOffset);
WOZread.data = woz_trks[track].data[trackOffset];
}
WOZread.shift16 <<= 1;
if ( WOZread.valid ) {
uint8_t byte = WOZread.shift;
// printf("%02X ", byte);
WOZread.shift = 0;
if (outdev) fprintf(outdev, "byte: %02X\n", byte);
return byte;
}
}
if (outdev) fprintf(outdev, "TIME OUT!\n");
// if (outdev) fprintf(outdev, "TIME OUT!\n");
}
return rand();