@@ -209,6 +209,8 @@ typedef int (*upd765_seektrack_cb)(int drive, int track, void* user_data);
209
209
typedef int (* upd765_seeksector_cb )(int drive , int side , upd765_sectorinfo_t * inout_info , void * user_data );
210
210
/* callback to read the next sector data byte */
211
211
typedef int (* upd765_read_cb )(int drive , int side , void * user_data , uint8_t * out_data );
212
+ /* callback to write the next sector data byte */
213
+ typedef int (* upd765_write_cb )(int drive , int side , void * user_data , uint8_t data );
212
214
/* callback to read info about first sector on current reack */
213
215
typedef int (* upd765_trackinfo_cb )(int drive , int side , void * user_data , upd765_sectorinfo_t * out_info );
214
216
/* callback to get info about disk drive (called on SENSE_DRIVE_STATUS command) */
@@ -219,6 +221,7 @@ typedef struct {
219
221
upd765_seektrack_cb seektrack_cb ;
220
222
upd765_seeksector_cb seeksector_cb ;
221
223
upd765_read_cb read_cb ;
224
+ upd765_write_cb write_cb ;
222
225
upd765_trackinfo_cb trackinfo_cb ;
223
226
upd765_driveinfo_cb driveinfo_cb ;
224
227
void * user_data ;
@@ -242,6 +245,7 @@ typedef struct {
242
245
upd765_seektrack_cb seektrack_cb ;
243
246
upd765_seeksector_cb seeksector_cb ;
244
247
upd765_read_cb read_cb ;
248
+ upd765_write_cb write_cb ;
245
249
upd765_trackinfo_cb trackinfo_cb ;
246
250
upd765_driveinfo_cb driveinfo_cb ;
247
251
void * user_data ;
@@ -394,6 +398,7 @@ static void _upd765_cmd(upd765_t* upd) {
394
398
CHIPS_ASSERT (upd -> phase == UPD765_PHASE_COMMAND );
395
399
switch (upd -> cmd ) {
396
400
case UPD765_CMD_READ_DATA :
401
+ case UPD765_CMD_WRITE_DATA :
397
402
{
398
403
upd -> st [0 ] = upd -> fifo [1 ] & 7 ; /* HD, US1, US0 */
399
404
upd -> sector_info .c = upd -> fifo [2 ];
@@ -528,7 +533,6 @@ static void _upd765_cmd(upd765_t* upd) {
528
533
break ;
529
534
530
535
case UPD765_CMD_READ_DELETED_DATA :
531
- case UPD765_CMD_WRITE_DATA :
532
536
case UPD765_CMD_WRITE_DELETED_DATA :
533
537
case UPD765_CMD_READ_A_TRACK :
534
538
case UPD765_CMD_FORMAT_A_TRACK :
@@ -575,9 +579,27 @@ static uint8_t _upd765_exec_rd(upd765_t* upd) {
575
579
576
580
/* called when a byte is written during the exec phase */
577
581
static void _upd765_exec_wr (upd765_t * upd , uint8_t data ) {
578
- // FIXME
579
- (void )upd ;
580
- (void )data ;
582
+ CHIPS_ASSERT (upd -> phase == UPD765_PHASE_EXEC );
583
+ switch (upd -> cmd ) {
584
+ case UPD765_CMD_WRITE_DATA :
585
+ {
586
+ /* write next sector data byte to FDD */
587
+ const int fdd_index = upd -> st [0 ] & 3 ;
588
+ const int side = (upd -> st [0 ] & 4 ) >> 2 ;
589
+ const int res = upd -> write_cb (fdd_index , side , upd -> user_data , data );
590
+ if (res != UPD765_RESULT_SUCCESS ) {
591
+ if (res & UPD765_RESULT_NOT_READY ) {
592
+ upd -> st [0 ] |= UPD765_ST0_NR ;
593
+ }
594
+ _upd765_to_phase_result (upd );
595
+ }
596
+ }
597
+ break ;
598
+ default :
599
+ /* shouldn't happen */
600
+ CHIPS_ASSERT (false);
601
+ break ;
602
+ }
581
603
}
582
604
583
605
/* write a data byte to the upd765 */
@@ -627,9 +649,6 @@ static inline uint8_t _upd765_read_status(upd765_t* upd) {
627
649
for between 2us and 50us, for now just indicate
628
650
that we're always ready during the command and result phase
629
651
*/
630
- /* FIXME: data direction is currently always set as FDC->CPU,
631
- since the emulation doesn't support write operations
632
- */
633
652
switch (upd -> phase ) {
634
653
case UPD765_PHASE_IDLE :
635
654
status |= UPD765_STATUS_RQM ;
@@ -638,7 +657,12 @@ static inline uint8_t _upd765_read_status(upd765_t* upd) {
638
657
status |= UPD765_STATUS_CB |UPD765_STATUS_RQM ;
639
658
break ;
640
659
case UPD765_PHASE_EXEC :
641
- status |= UPD765_STATUS_CB |UPD765_STATUS_EXM |UPD765_STATUS_DIO |UPD765_STATUS_RQM ;
660
+ status |= UPD765_STATUS_CB |UPD765_STATUS_EXM |UPD765_STATUS_RQM ;
661
+ // NOTE: the DIO bit is associated with fifo_write and internal_drq
662
+ // booleans in MAME, so it's a bit more complicated than what we do here
663
+ if (upd -> cmd != UPD765_CMD_WRITE_DATA ) {
664
+ status |= UPD765_STATUS_DIO ;
665
+ }
642
666
break ;
643
667
case UPD765_PHASE_RESULT :
644
668
status |= UPD765_STATUS_CB |UPD765_STATUS_DIO |UPD765_STATUS_RQM ;
@@ -658,6 +682,7 @@ void upd765_init(upd765_t* upd, const upd765_desc_t* desc) {
658
682
upd -> seektrack_cb = desc -> seektrack_cb ;
659
683
upd -> seeksector_cb = desc -> seeksector_cb ;
660
684
upd -> read_cb = desc -> read_cb ;
685
+ upd -> write_cb = desc -> write_cb ;
661
686
upd -> trackinfo_cb = desc -> trackinfo_cb ;
662
687
upd -> driveinfo_cb = desc -> driveinfo_cb ;
663
688
upd -> user_data = desc -> user_data ;
0 commit comments