From f33378034858e13b610926a747c74c2e152a6b87 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Fri, 22 Feb 2019 00:21:05 -0500 Subject: [PATCH] fixed bit length of tracks; added actual random fake bits. Passes most test Woz images now. --- apple/woz.cpp | 29 +++++++++++++++++++++++------ apple/woz.h | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apple/woz.cpp b/apple/woz.cpp index 81f7faf..82d5375 100644 --- a/apple/woz.cpp +++ b/apple/woz.cpp @@ -30,6 +30,7 @@ Woz::Woz() { trackPointer = 0; trackBitIdx = 0x80; + trackBitCounter = 0; trackLoopCounter = 0; metaData = NULL; @@ -39,6 +40,7 @@ Woz::Woz() memset(&quarterTrackMap, 255, sizeof(quarterTrackMap)); memset(&di, 0, sizeof(diskInfo)); memset(&tracks, 0, sizeof(tracks)); + randPtr = 0; } Woz::~Woz() @@ -70,12 +72,17 @@ uint8_t Woz::getNextWozBit(uint8_t track) } // need another byte out of the track stream trackByte = tracks[track].trackData[trackPointer++]; - if (trackPointer >= tracks[track].bitCount / 8) { - trackPointer = 0; - trackLoopCounter++; - } } + if (trackBitCounter >= tracks[track].bitCount) { + trackPointer = 0; + trackBitIdx = 0x80; + trackLoopCounter++; + trackByte = tracks[track].trackData[trackPointer++]; + trackBitCounter = 0; + } + trackBitCounter++; + uint8_t ret = (trackByte & trackBitIdx) ? 1 : 0; trackBitIdx >>= 1; @@ -88,8 +95,18 @@ uint8_t Woz::getNextWozBit(uint8_t track) uint8_t Woz::fakeBit() { - // 30% should be 1s - return 0; + // 30% should be 1s, but I'm not biasing the data here, so this is + // more like 50% 1s. + + if (randPtr == 0) { + randPtr = 0x80; + randData = (uint8_t) ((float)256*rand()/(RAND_MAX+1.0)); + } + + uint8_t ret = (randData & randPtr) ? 1 : 0; + randPtr >>= 1; + + return ret; } uint8_t Woz::nextDiskBit(uint8_t track) diff --git a/apple/woz.h b/apple/woz.h index fd518f8..ffe3fda 100644 --- a/apple/woz.h +++ b/apple/woz.h @@ -90,10 +90,12 @@ class Woz { // cursor for track enumeration uint32_t trackPointer; + uint32_t trackBitCounter; uint8_t trackByte; uint8_t trackBitIdx; uint8_t trackLoopCounter; char *metaData; + uint8_t randData, randPtr; }; #endif