Skip to content

Commit a17253f

Browse files
keirftdaede
authored andcommitted
Add disk inserted sensor pin interface option.
"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).
1 parent bc5e2c4 commit a17253f

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

examples/FF.CFG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ host = unspecified
5151
# ndens: Logical complement of above
5252
# chg: Disk changed (Changed = 0v)
5353
# nchg: Logical complement of above
54-
# Values: auto, nc, low, high, rdy, nrdy, dens, ndens, chg, nchg
54+
# in: Disk inserted (Inserted = 0v), ignores drive-select
55+
# nin: Logical complement of above
56+
# Values: auto, nc, low, high, rdy, nrdy, dens, ndens, chg, nchg, in, nin
5557
pin02 = auto
5658
pin34 = auto
5759

inc/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ struct packed ff_cfg {
130130
#define PIN_rdy (outp_rdy + 1)
131131
#define PIN_dens (outp_hden + 1)
132132
#define PIN_chg (outp_dskchg + 1)
133+
#define PIN_in (outp_in + 1)
133134
#define PIN_invert 0x80
134135
#define PIN_low (PIN_high | PIN_invert)
135136
#define PIN_nrdy (PIN_rdy | PIN_invert)
136137
#define PIN_ndens (PIN_dens | PIN_invert)
137138
#define PIN_nchg (PIN_chg | PIN_invert)
139+
#define PIN_nin (PIN_in | PIN_invert)
138140
uint8_t pin02, pin34;
139141
uint8_t head_settle_ms;
140142
uint8_t oled_contrast;

inc/floppy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#define outp_wrprot 3
3636
#define outp_rdy 4
3737
#define outp_hden 5
38-
#define outp_nr 6
38+
#define outp_in 6
39+
#define outp_nr 7
3940
#define outp_unused outp_nr
4041

4142
#define verbose_image_log FALSE

src/floppy.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static always_inline void drive_change_pin(
3838
struct drive *drv, uint8_t pin, bool_t assert);
3939
static always_inline void drive_change_output(
4040
struct drive *drv, uint8_t outp, bool_t assert);
41+
static void disk_inserted_output(uint8_t outp, bool_t assert);
4142

4243
#include "floppy_generic.c"
4344

@@ -130,6 +131,18 @@ static void drive_change_output(
130131
drive_change_pin(drv, pin, assert);
131132
}
132133

134+
static void disk_inserted_output(uint8_t outp, bool_t assert)
135+
{
136+
if (pin02 == outp) {
137+
GPIO gpio = pin_02 < 16 ? gpiob : gpioa;
138+
gpio_write_pin(gpio, pin_02 & 15, assert ^ pin02_inverted);
139+
}
140+
if (pin34 == outp) {
141+
GPIO gpio = pin_34 < 16 ? gpiob : gpioa;
142+
gpio_write_pin(gpio, pin_34 & 15, assert ^ pin34_inverted);
143+
}
144+
}
145+
133146
static void update_amiga_id(struct drive *drv, bool_t amiga_hd_id)
134147
{
135148
/* JC and pin 34 are overridden only for the Amiga interface. */
@@ -210,6 +223,7 @@ void floppy_cancel(void)
210223
barrier();
211224
drive_change_output(drv, outp_index, FALSE);
212225
drive_change_output(drv, outp_dskchg, TRUE);
226+
disk_inserted_output(outp_in, TRUE);
213227
}
214228

215229
void floppy_set_fintf_mode(void)
@@ -223,6 +237,7 @@ void floppy_set_fintf_mode(void)
223237
[FINTF_AMIGA] = "Amiga"
224238
};
225239
static const char *const outp_name[] = {
240+
[outp_in] = "in",
226241
[outp_dskchg] = "chg",
227242
[outp_rdy] = "rdy",
228243
[outp_hden] = "dens",
@@ -320,6 +335,7 @@ void floppy_init(void)
320335
drive_change_output(drv, outp_dskchg, TRUE);
321336
drive_change_output(drv, outp_wrprot, TRUE);
322337
drive_change_output(drv, outp_trk0, TRUE);
338+
disk_inserted_output(outp_in, TRUE);
323339

324340
floppy_init_irqs();
325341

@@ -352,6 +368,7 @@ void floppy_insert(unsigned int unit, struct slot *slot)
352368
update_amiga_id(drv, im->stk_per_rev > stk_ms(300));
353369
if (!(slot->attributes & AM_RDO))
354370
drive_change_output(drv, outp_wrprot, FALSE);
371+
disk_inserted_output(outp_in, FALSE);
355372
barrier();
356373
drv->inserted = TRUE;
357374
motor_chgrst_update_status(drv); /* update RDY + motor state */

src/gotek/floppy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ static void IRQ_STEP_changed(void)
305305

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

311312
/* Do we accept this STEP command? */
312313
if ((drv->step.state & STEP_active) /* Already mid-step? */

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ static uint8_t parse_pin_str(const char *s)
911911
: !strcmp(s, "rdy") ? PIN_rdy
912912
: !strcmp(s, "dens") ? PIN_dens
913913
: !strcmp(s, "chg") ? PIN_chg
914+
: !strcmp(s, "in") ? PIN_in
914915
: PIN_auto;
915916
return pin;
916917
}

0 commit comments

Comments
 (0)