mirror of
https://github.com/ivanizag/izapple2.git
synced 2024-05-28 12:41:27 +00:00
Support fake bits in WOZ
This commit is contained in:
parent
53e7a07a46
commit
b9f893f96b
|
@ -1,5 +1,7 @@
|
||||||
package apple2
|
package apple2
|
||||||
|
|
||||||
|
import "math/rand"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
See:
|
See:
|
||||||
https://applesaucefdc.com/woz/
|
https://applesaucefdc.com/woz/
|
||||||
|
@ -26,7 +28,7 @@ Emulation status for the disk used on the reference:
|
||||||
- Crisis Mountain: Working
|
- Crisis Mountain: Working
|
||||||
- Miner 2049er II: Working
|
- Miner 2049er II: Working
|
||||||
- When bits aren't really bits
|
- When bits aren't really bits
|
||||||
- *** The Print Shop Companion: Not working
|
- The Print Shop Companion: Working
|
||||||
- What is the lifespan of the data latch?
|
- What is the lifespan of the data latch?
|
||||||
- *** First Math Adventures - Understanding Word Problems
|
- *** First Math Adventures - Understanding Word Problems
|
||||||
- Reading Offset Data Streams
|
- Reading Offset Data Streams
|
||||||
|
@ -44,6 +46,8 @@ type disketteWoz struct {
|
||||||
cycle uint64
|
cycle uint64
|
||||||
trackSize uint32
|
trackSize uint32
|
||||||
|
|
||||||
|
mc3470Buffer uint8 // Four bit buffer to detect weak bits and to add latency
|
||||||
|
|
||||||
visibleLatch uint8
|
visibleLatch uint8
|
||||||
visibleLatchCountDown int8 // The visible latch stores a valid latch reading for 2 bit timings
|
visibleLatchCountDown int8 // The visible latch stores a valid latch reading for 2 bit timings
|
||||||
}
|
}
|
||||||
|
@ -65,8 +69,17 @@ func (d *disketteWoz) read(quarterTrack int, cycle uint64) uint8 {
|
||||||
// Process bits from woz
|
// Process bits from woz
|
||||||
// TODO: avoid processing too many bits if delta is big
|
// TODO: avoid processing too many bits if delta is big
|
||||||
for i := uint64(0); i < deltaBits; i++ {
|
for i := uint64(0); i < deltaBits; i++ {
|
||||||
|
// Get next bit taking into account the MC3470 latency and weak bits
|
||||||
d.position++
|
d.position++
|
||||||
bit := d.data.getBit(d.position, quarterTrack)
|
fluxBit := d.data.getBit(d.position, quarterTrack)
|
||||||
|
d.mc3470Buffer = (d.mc3470Buffer<<1 + fluxBit) & 0x0f
|
||||||
|
bit := (d.mc3470Buffer >> 1) & 0x1 // Use the previous to last bit to add latency
|
||||||
|
if d.mc3470Buffer == 0 && rand.Intn(100) < 3 {
|
||||||
|
// Four consecutive zeros.It'a a fake bit.
|
||||||
|
// Output a random value. 70% zero, 30% one
|
||||||
|
bit = 1
|
||||||
|
}
|
||||||
|
|
||||||
d.latch = (d.latch << 1) + bit
|
d.latch = (d.latch << 1) + bit
|
||||||
if d.latch >= 0x80 {
|
if d.latch >= 0x80 {
|
||||||
// Valid byte, store value a bit longer and clear the internal latch
|
// Valid byte, store value a bit longer and clear the internal latch
|
||||||
|
|
Loading…
Reference in New Issue
Block a user