mirror of
https://github.com/trudnai/Steve2.git
synced 2024-12-13 08:29:30 +00:00
Clean up woz_read()
This commit is contained in:
parent
e414e13ad4
commit
e6e43df201
@ -205,260 +205,6 @@ uint8_t woz_read() {
|
||||
return rand();
|
||||
}
|
||||
|
||||
#ifdef WOZ_REAL_SPIN
|
||||
if ( track != track_loaded ) {
|
||||
woz_loadTrack(track);
|
||||
track_loaded = track;
|
||||
}
|
||||
|
||||
WOZread.shift32 = 0;
|
||||
bitOffset = (m6502.clktime >> 2) & 7;
|
||||
trackOffset = (m6502.clktime >> 5) % WOZ_TRACK_BYTE_COUNT;
|
||||
WOZread.next = woz_trks[track].data[ (trackOffset +1) % WOZ_TRACK_BYTE_COUNT ];
|
||||
WOZread.data = woz_trks[track].data[ trackOffset ];
|
||||
WOZread.prev = woz_trks[track].data[ (trackOffset -1) % WOZ_TRACK_BYTE_COUNT ];
|
||||
WOZread.shift = woz_trks[track].data[ (trackOffset -2) % WOZ_TRACK_BYTE_COUNT ];
|
||||
|
||||
printf("clk:%llu bo:%u to:%u W:%08X\n", m6502.clktime, bitOffset, trackOffset, WOZread.shift32);
|
||||
|
||||
uint8_t state = 0;
|
||||
// simulating the continous shift register in Disk ][
|
||||
for (int i = bitOffset + 16; i; --i) {
|
||||
|
||||
WOZread.shift32 <<= 1;
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
WOZlatch = WOZread.shift;
|
||||
if ( WOZread.valid ) {
|
||||
state = 1;
|
||||
WOZread.shift = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// we do not latch the shift register for one 4us cycle
|
||||
state = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
// this should not happen
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// printf("shft1: W:%08X L:%02X\n", WOZread.shift32, WOZlatch);
|
||||
|
||||
}
|
||||
|
||||
printf("clk:%llu bo:%u to:%u W:%08X B:%02X\n", m6502.clktime, bitOffset, trackOffset, WOZread.shift32, WOZlatch);
|
||||
if ( WOZlatch & 0x80 ) {
|
||||
printf("WOZlatch: %02X\n", WOZlatch);
|
||||
|
||||
static int readState = 0;
|
||||
static int vol = 0;
|
||||
static int trk = 0;
|
||||
static int sec = 0;
|
||||
|
||||
switch (readState) {
|
||||
case 0:
|
||||
if ( 0xD5 == WOZlatch ) readState = 1;
|
||||
else readState = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if ( 0xAA == WOZlatch ) readState = 2;
|
||||
else readState = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if ( 0x96 == WOZlatch ) {
|
||||
readState = 3;
|
||||
printf("sector header marker\n");
|
||||
}
|
||||
else if ( 0xAD == WOZlatch ) {
|
||||
readState = 10;
|
||||
printf("sector data marker\n");
|
||||
}
|
||||
else readState = 0;
|
||||
break;
|
||||
|
||||
case 3: // sector header, vol number 1
|
||||
readState++;
|
||||
vol = (WOZlatch << 1) | 1;
|
||||
break;
|
||||
|
||||
case 4: // sector header, vol number 2
|
||||
readState++;
|
||||
vol &= WOZlatch;
|
||||
printf("vol:%u ", vol);
|
||||
break;
|
||||
|
||||
case 5: // sector header, trk number 1
|
||||
readState++;
|
||||
trk = (WOZlatch << 1) | 1;
|
||||
break;
|
||||
|
||||
case 6: // sector header, trk number 2
|
||||
readState++;
|
||||
trk &= WOZlatch;
|
||||
printf("trk:%u ", trk);
|
||||
break;
|
||||
|
||||
case 7: // sector header, sec number 1
|
||||
readState++;
|
||||
sec = (WOZlatch << 1) | 1;
|
||||
break;
|
||||
|
||||
case 8: // sector header, sec number 2
|
||||
readState = 0;
|
||||
sec &= WOZlatch;
|
||||
printf("sec:%u\n", sec);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
readState = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// switch ( WOZlatch ) {
|
||||
// case 0xAA:
|
||||
// case 0x96:
|
||||
//// printf("%02X ", WOZlatch);
|
||||
// printf("clk:%llu bo:%u to:%u B:%02X\n", m6502.clktime, bitOffset, trackOffset, WOZlatch);
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
return WOZlatch;
|
||||
|
||||
|
||||
#elif defined( WOZ_REAL_SPIN2 )
|
||||
// clkelpased = m6502.clktime - disk.clk_last_read;
|
||||
// disk.clk_last_read = m6502.clktime;
|
||||
|
||||
bitOffset = (m6502.clktime >> 2) & 7;
|
||||
trackOffset = (m6502.clktime >> 5) % WOZ_TRACK_BYTE_COUNT;
|
||||
trackEntry_t reg = prepared_track[trackOffset];
|
||||
|
||||
do {
|
||||
switch (readState) {
|
||||
case readNormal:
|
||||
readLatch = reg.shift;
|
||||
break;
|
||||
|
||||
case readHold:
|
||||
default:
|
||||
readState = readNormal;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reg.shift & 0x80) {
|
||||
reg.shift = 0;
|
||||
readState = readHold;
|
||||
}
|
||||
|
||||
reg.shift16 <<= 1;
|
||||
} while ( --bitOffset > 0 );
|
||||
|
||||
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;
|
||||
|
||||
clkelpased = m6502.clktime + clkfrm - m6502.clklast;
|
||||
@ -546,9 +292,6 @@ uint8_t woz_read() {
|
||||
}
|
||||
|
||||
return rand();
|
||||
|
||||
#endif // WOZ_REAL_SPIN
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user