Adafruit Library
Public Types | Public Member Functions | List of all members
Adafruit_Apple2Floppy Class Reference

A helper class for chattin with Apple 2 floppy drives. More...

#include <Adafruit_Floppy.h>

Inheritance diagram for Adafruit_Apple2Floppy:
Adafruit_FloppyBase

Public Types

enum  StepMode { STEP_MODE_WHOLE, STEP_MODE_HALF, STEP_MODE_QUARTER }
 Constants for use with the step_mode method.
 

Public Member Functions

 Adafruit_Apple2Floppy (int8_t indexpin, int8_t selectpin, int8_t phase1pin, int8_t phase2pin, int8_t phase3pin, int8_t phase4pin, int8_t wrdatapin, int8_t wrgatepin, int8_t protectpin, int8_t rddatapin)
 Create a hardware interface to a floppy drive. More...
 
void end () override
 Disables floppy communication, allowing pins to be used for general input and output.
 
void soft_reset (void) override
 Initializes the GPIO pins but do not start the motor or anything.
 
void select (bool selected) override
 Whether to select this drive. More...
 
bool spin_motor (bool motor_on) override
 Wait for index pulse. More...
 
bool goto_track (int track) override
 Seek to the desired track, requires the motor to be spun up! More...
 
bool side (int head) override
 Which head/side to read from. More...
 
int track (void) override
 The current track location, based on internal caching. More...
 
bool set_density (bool high_density) override
 Set the density for flux reading and writing. More...
 
bool get_write_protect () override
 Check the write protect status of the floppy. More...
 
bool get_track0_sense () override
 Check whether the track0 sensor is active. More...
 
bool get_ready_sense () override
 Check whether the ready output is active. More...
 
int quartertrack ()
 Get the drive position in quarter tracks. More...
 
bool goto_quartertrack (int)
 Seek to the desired quarter track, requires the motor to be spun up! More...
 
void step_mode (StepMode mode)
 Set the positioning mode. More...
 
int get_side () override
 Current head in use, based on internal caching. More...
 
- Public Member Functions inherited from Adafruit_FloppyBase
bool begin (void)
 Initializes the GPIO pins but do not start the motor or anything. More...
 
size_t decode_track_mfm (uint8_t *sectors, size_t n_sectors, uint8_t *sector_validity, const uint8_t *pulses, size_t n_pulses, float nominal_bit_time_us, bool clear_validity=false, uint8_t *logical_track=nullptr)
 Decode one track of previously captured MFM data. More...
 
size_t encode_track_mfm (const uint8_t *sectors, size_t n_sectors, uint8_t *pulses, size_t max_pulses, float nominal_bit_time_us, uint8_t logical_track)
 Encode one track of previously captured MFM data. More...
 
size_t capture_track (volatile uint8_t *pulses, size_t max_pulses, int32_t *falling_index_offset, bool store_greaseweazle=false, uint32_t capture_ms=0, uint32_t index_wait_ms=250) __attribute__((optimize("O3")))
 Capture one track's worth of flux transitions, between two falling index pulses. More...
 
bool write_track (uint8_t *pulses, size_t n_pulses, bool store_greaseweazle=false, bool use_index=true) __attribute__((optimize("O3")))
 Write one track of flux pulse data, starting at the index pulse. More...
 
void print_pulse_bins (uint8_t *pulses, size_t n_pulses, uint8_t max_bins=64, bool is_gw_format=false, uint32_t min_bin_size=100)
 Pretty print a simple histogram of flux transitions. More...
 
void print_pulses (uint8_t *pulses, size_t n_pulses, bool is_gw_format=false)
 Pretty print the counts in a list of flux transitions. More...
 
uint32_t getSampleFrequency (void)
 Get the sample rate that we read and emit pulses at, platform and implementation-dependant. More...
 

Additional Inherited Members

- Public Attributes inherited from Adafruit_FloppyBase
int8_t led_pin = -1
 Debug LED output for tracing.
 
uint16_t select_delay_us = 10
 delay after drive select (usecs)
 
uint16_t step_delay_us = 10000
 delay between head steps (usecs)
 
uint16_t settle_delay_ms = 15
 settle delay after seek (msecs)
 
uint16_t motor_delay_ms = 1000
 delay after motor on (msecs)
 
uint16_t watchdog_delay_ms
 quiescent time until drives reset (msecs) More...
 
uint8_t bus_type = BUSTYPE_IBMPC
 what kind of floppy drive we're using
 
Stream * debug_serial = nullptr
 optional debug stream for serial output
 
- Protected Member Functions inherited from Adafruit_FloppyBase
 Adafruit_FloppyBase (int indexpin, int wrdatapin, int wrgatepin, int rddatapin, bool is_apple2=false)
 Create a hardware interface to a floppy drive. More...
 
bool read_index ()
 Poll the status of the index pulse. More...
 

Detailed Description

A helper class for chattin with Apple 2 floppy drives.

Constructor & Destructor Documentation

◆ Adafruit_Apple2Floppy()

Adafruit_Apple2Floppy::Adafruit_Apple2Floppy ( int8_t  indexpin,
int8_t  selectpin,
int8_t  phase1pin,
int8_t  phase2pin,
int8_t  phase3pin,
int8_t  phase4pin,
int8_t  wrdatapin,
int8_t  wrgatepin,
int8_t  protectpin,
int8_t  rddatapin 
)

Create a hardware interface to a floppy drive.

Parameters
indexpinA pin connected to the floppy Index Sensor output
selectpinA pin connected to the floppy Drive Select input
phase1pinA pin connected to the floppy "phase 1" output
phase2pinA pin connected to the floppy "phase 2" output
phase3pinA pin connected to the floppy "phase 3" output
phase4pinA pin connected to the floppy "phase 4" output
wrdatapinA pin connected to the floppy Write Data input
wrgatepinA pin connected to the floppy Write Gate input
protectpinA pin connected to the floppy Write Protect Sensor output
rddatapinA pin connected to the floppy Read Data output

Member Function Documentation

◆ select()

void Adafruit_Apple2Floppy::select ( bool  selected)
overridevirtual

Whether to select this drive.

Parameters
selectedTrue to select/enable

Implements Adafruit_FloppyBase.

◆ spin_motor()

bool Adafruit_Apple2Floppy::spin_motor ( bool  motor_on)
overridevirtual

Wait for index pulse.

Parameters
motor_onTrue to wait for index pulse, false to do nothing
Returns
False if turning motor on and no index pulse found, true otherwise
Note
The Apple II floppy has a single "select/enable" pin which selects the drive and turns on the spindle.

Implements Adafruit_FloppyBase.

◆ goto_track()

bool Adafruit_Apple2Floppy::goto_track ( int  track_num)
overridevirtual

Seek to the desired track, requires the motor to be spun up!

Parameters
track_numThe track to step to
Returns
True If we were able to get to the track location

Implements Adafruit_FloppyBase.

◆ side()

bool Adafruit_Apple2Floppy::side ( int  head)
overridevirtual

Which head/side to read from.

Parameters
headHead must be 0
Returns
true if the head is 0, false otherwise
Note
Apple II floppy drives only have a single side

Implements Adafruit_FloppyBase.

◆ track()

int Adafruit_Apple2Floppy::track ( void  )
overridevirtual

The current track location, based on internal caching.

Returns
The cached track location
Note
Partial tracks are rounded, with quarter tracks always rounded down.

Implements Adafruit_FloppyBase.

◆ set_density()

bool Adafruit_Apple2Floppy::set_density ( bool  high_density)
overridevirtual

Set the density for flux reading and writing.

Parameters
high_densitytrue to select high density, false to select low density.
Returns
true if low density mode is selected, false if high density is selected
Note
The drive hardware is only capable of single density operation

Implements Adafruit_FloppyBase.

◆ get_write_protect()

bool Adafruit_Apple2Floppy::get_write_protect ( void  )
overridevirtual

Check the write protect status of the floppy.

Returns
true if the floppy is write protected, false otherwise
Note
The write protect circuit in the Apple II floppy drive is "interesting". Because of how it was read by the Apple II Disk Interface Card, the protect output is only active when the "phase 1" winding is energized; having the "phase 1" winding active also prevents writing, but at the Disk Interface Card, not at the drive. So, it's necessary for us to check write_protected in software!

If_protectpin is -1 (not available), then we always report that the disk is write protected.

Implements Adafruit_FloppyBase.

◆ get_track0_sense()

bool Adafruit_Apple2Floppy::get_track0_sense ( void  )
overridevirtual

Check whether the track0 sensor is active.

Returns
True if the track0 sensor is active, false otherwise
Note
This device has no home sensor so it just returns track() == 0.

Implements Adafruit_FloppyBase.

◆ get_ready_sense()

bool Adafruit_Apple2Floppy::get_ready_sense ( )
inlineoverridevirtual

Check whether the ready output is active.

Returns
True if the ready sensor is active, false otherwise
Note
On devices without a ready sensor, this always returns true

Implements Adafruit_FloppyBase.

◆ quartertrack()

int Adafruit_Apple2Floppy::quartertrack ( )

Get the drive position in quarter tracks.

Returns
True if the track0 sensor is active, false otherwise
Note
Returns -1 if the position is unknown

◆ goto_quartertrack()

bool Adafruit_Apple2Floppy::goto_quartertrack ( int  quartertrack)

Seek to the desired quarter track, requires the motor to be spun up!

Parameters
quartertrackThe position to step to
Returns
True If we were able to get to the track location

◆ step_mode()

void Adafruit_Apple2Floppy::step_mode ( StepMode  step_mode)

Set the positioning mode.

Parameters
step_modeThe new positioning mode
Note
This does not re-position the drive

◆ get_side()

int Adafruit_Apple2Floppy::get_side ( )
inlineoverridevirtual

Current head in use, based on internal caching.

Returns
Head 0 or 1

Implements Adafruit_FloppyBase.


The documentation for this class was generated from the following files: