Skip to content

Commit dadc697

Browse files
committed
fix(fdc): seek and recalibrate set drive number in ST0
- Removed one TODO with kinda working implementation - Improved seek test by removing edge case - Can be further improved, ad the moment sequential seek/recalibrate without interleaved sense interrupt are not supported
1 parent 9be9ccb commit dadc697

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/fdc.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -471,24 +471,21 @@ static void pre_exec_recalibrate(void) {
471471

472472
// We don't have to actually move the head. The drive is immediately ready
473473
int_status = true;
474+
// Update the status register with the drive info and the seek end flag
475+
status_register[ST0] = drive;
474476
}
475477

476478
// Sense interrupt:
477479
static void post_exec_sense_interrupt(void) {
478-
// TODO(giuliof): last accessed drive
479-
uint8_t drive = 0;
480+
// Last accessed drive number is in ST0
481+
uint8_t drive = status_register[ST0] & FDC_ST0_US;
480482

481483
// After reading interrupt status, ready can be deasserted
482484
int_status = false;
483485

484486
LOG_DEBUG("FDC Sense Interrupt\n");
485487
/* Status Register 0 */
486-
// Drive number
487-
result[0] = drive;
488-
// head address (last addressed) - TODO(giulio)
489-
// result[0] |= ...;
490-
// Seek End - TODO(giulio)
491-
result[0] |= FDC_ST0_SE;
488+
result[0] = status_register[ST0] | FDC_ST0_SE;
492489
/* PCN - (current track position) */
493490
result[1] = track[drive];
494491
}
@@ -617,6 +614,8 @@ static void pre_exec_seek(void) {
617614

618615
// We don't have to actually move the head. The drive is immediately ready
619616
int_status = true;
617+
// Update the status register with the drive info and the seek end flag
618+
status_register[ST0] = drive;
620619
}
621620

622621
/* * * * * * * * * * * * * * * Utility routines * * * * * * * * * * * * * * */

src/tests/test_fdc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Test(ceda_fdc, seekCommand) {
113113
assert_fdc_sr(FDC_ST_RQM | FDC_ST_CB);
114114

115115
// First argument is number of drive
116-
fdc_out(FDC_ADDR_DATA_REGISTER, 0x00);
116+
fdc_out(FDC_ADDR_DATA_REGISTER, 0x02);
117117
// Second argument is cylinder position
118118
fdc_out(FDC_ADDR_DATA_REGISTER, 5);
119119

@@ -132,7 +132,7 @@ Test(ceda_fdc, seekCommand) {
132132

133133
// First response byte is SR0 with interrupt code = 0 and Seek End = 1
134134
data = fdc_in(FDC_ADDR_DATA_REGISTER);
135-
cr_expect_eq(data, FDC_ST0_SE);
135+
cr_expect_eq(data, FDC_ST0_SE | 2);
136136

137137
// FDC has another byte of response
138138
assert_fdc_sr(FDC_ST_RQM | FDC_ST_DIO | FDC_ST_CB);

0 commit comments

Comments
 (0)