Skip to content

Commit

Permalink
Add disk inserted sensor pin interface option.
Browse files Browse the repository at this point in the history
"in" and "nin" can configure a pin to indicate the status of
the disk inserted sensor. This ignores the drive select pin.

This is intended to be used with the Sharp X68000 (with the
addition of additional hardware - on the X68000 this is gated
by the OPTION SELECT line).
  • Loading branch information
keirf authored and tdaede committed Apr 24, 2023
1 parent bc5e2c4 commit a17253f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/FF.CFG
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ host = unspecified
# ndens: Logical complement of above
# chg: Disk changed (Changed = 0v)
# nchg: Logical complement of above
# Values: auto, nc, low, high, rdy, nrdy, dens, ndens, chg, nchg
# in: Disk inserted (Inserted = 0v), ignores drive-select
# nin: Logical complement of above
# Values: auto, nc, low, high, rdy, nrdy, dens, ndens, chg, nchg, in, nin
pin02 = auto
pin34 = auto

Expand Down
2 changes: 2 additions & 0 deletions inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ struct packed ff_cfg {
#define PIN_rdy (outp_rdy + 1)
#define PIN_dens (outp_hden + 1)
#define PIN_chg (outp_dskchg + 1)
#define PIN_in (outp_in + 1)
#define PIN_invert 0x80
#define PIN_low (PIN_high | PIN_invert)
#define PIN_nrdy (PIN_rdy | PIN_invert)
#define PIN_ndens (PIN_dens | PIN_invert)
#define PIN_nchg (PIN_chg | PIN_invert)
#define PIN_nin (PIN_in | PIN_invert)
uint8_t pin02, pin34;
uint8_t head_settle_ms;
uint8_t oled_contrast;
Expand Down
3 changes: 2 additions & 1 deletion inc/floppy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#define outp_wrprot 3
#define outp_rdy 4
#define outp_hden 5
#define outp_nr 6
#define outp_in 6
#define outp_nr 7
#define outp_unused outp_nr

#define verbose_image_log FALSE
Expand Down
17 changes: 17 additions & 0 deletions src/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static always_inline void drive_change_pin(
struct drive *drv, uint8_t pin, bool_t assert);
static always_inline void drive_change_output(
struct drive *drv, uint8_t outp, bool_t assert);
static void disk_inserted_output(uint8_t outp, bool_t assert);

#include "floppy_generic.c"

Expand Down Expand Up @@ -130,6 +131,18 @@ static void drive_change_output(
drive_change_pin(drv, pin, assert);
}

static void disk_inserted_output(uint8_t outp, bool_t assert)
{
if (pin02 == outp) {
GPIO gpio = pin_02 < 16 ? gpiob : gpioa;
gpio_write_pin(gpio, pin_02 & 15, assert ^ pin02_inverted);
}
if (pin34 == outp) {
GPIO gpio = pin_34 < 16 ? gpiob : gpioa;
gpio_write_pin(gpio, pin_34 & 15, assert ^ pin34_inverted);
}
}

static void update_amiga_id(struct drive *drv, bool_t amiga_hd_id)
{
/* JC and pin 34 are overridden only for the Amiga interface. */
Expand Down Expand Up @@ -210,6 +223,7 @@ void floppy_cancel(void)
barrier();
drive_change_output(drv, outp_index, FALSE);
drive_change_output(drv, outp_dskchg, TRUE);
disk_inserted_output(outp_in, TRUE);
}

void floppy_set_fintf_mode(void)
Expand All @@ -223,6 +237,7 @@ void floppy_set_fintf_mode(void)
[FINTF_AMIGA] = "Amiga"
};
static const char *const outp_name[] = {
[outp_in] = "in",
[outp_dskchg] = "chg",
[outp_rdy] = "rdy",
[outp_hden] = "dens",
Expand Down Expand Up @@ -320,6 +335,7 @@ void floppy_init(void)
drive_change_output(drv, outp_dskchg, TRUE);
drive_change_output(drv, outp_wrprot, TRUE);
drive_change_output(drv, outp_trk0, TRUE);
disk_inserted_output(outp_in, TRUE);

floppy_init_irqs();

Expand Down Expand Up @@ -352,6 +368,7 @@ void floppy_insert(unsigned int unit, struct slot *slot)
update_amiga_id(drv, im->stk_per_rev > stk_ms(300));
if (!(slot->attributes & AM_RDO))
drive_change_output(drv, outp_wrprot, FALSE);
disk_inserted_output(outp_in, FALSE);
barrier();
drv->inserted = TRUE;
motor_chgrst_update_status(drv); /* update RDY + motor state */
Expand Down
3 changes: 2 additions & 1 deletion src/gotek/floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ static void IRQ_STEP_changed(void)

/* Deassert DSKCHG if a disk is inserted. */
if ((drv->outp & m(outp_dskchg)) && drv->inserted
&& (ff_cfg.chgrst == CHGRST_step))
&& (ff_cfg.chgrst == CHGRST_step)) {
drive_change_output(drv, outp_dskchg, FALSE);
}

/* Do we accept this STEP command? */
if ((drv->step.state & STEP_active) /* Already mid-step? */
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ static uint8_t parse_pin_str(const char *s)
: !strcmp(s, "rdy") ? PIN_rdy
: !strcmp(s, "dens") ? PIN_dens
: !strcmp(s, "chg") ? PIN_chg
: !strcmp(s, "in") ? PIN_in
: PIN_auto;
return pin;
}
Expand Down

0 comments on commit a17253f

Please sign in to comment.