From: <sba...@us...> - 2023-10-21 10:28:55
|
This is an automated email from the git hooks/post-receive-user script. sbaldovi pushed a commit to branch master in repository fuse. View the commit online: https://sourceforge.net/p/fuse-emulator/fuse/ci/84f7feba545b5d7570c87f07a0e9928dd66da5ad/ commit 84f7feba545b5d7570c87f07a0e9928dd66da5ad Author: Gergely Szasz <sz...@hu...> AuthorDate: Sat Oct 21 07:52:44 2023 +0200 Add debugging info in uPD765 FDC (more from bug #453) (thanks, Vic Chwe). --- peripherals/disk/upd_fdc.c | 151 ++++++++++++++++++++++++++++++++++++++++++++- peripherals/disk/upd_fdc.h | 7 ++- 2 files changed, 156 insertions(+), 2 deletions(-) diff --git a/peripherals/disk/upd_fdc.c b/peripherals/disk/upd_fdc.c index 9e10e87c..64d9974c 100644 --- a/peripherals/disk/upd_fdc.c +++ b/peripherals/disk/upd_fdc.c @@ -33,6 +33,34 @@ #define MAX_SIZE_CODE 8 +#ifdef DEBUG_UPD +const char *debug_cmd_str[] = { + "INVALID", + "--", + "READ_DIAG", + "SPECIFY", + "SENSE_DRIVE", + "WRITE_DATA", + "READ_DATA", + "RECALIBRATE", + "SENSE_INTERRUPT", + "WRITE_DATA_DEL", + "READ_ID", + "--", + "READ_DATA_DEL", + "WRITE_ID", + "--", + "SEEK", + "VERSION", + "SCAN_EQ", + "--","--","--","--","--","--","--", + "SCAN_LE", + "--","--","--", + "SCAN_HE", + "--","--" +}; +#endif + /* static const int UPD_FDC_MAIN_DRV_0_SEEK = 0x01; */ /* static const int UPD_FDC_MAIN_DRV_1_SEEK = 0x02; */ /* static const int UPD_FDC_MAIN_DRV_2_SEEK = 0x04; */ @@ -901,9 +929,53 @@ upd_fdc_event( libspectrum_dword last_tstates GCC_UNUSED, int event, return; } +#ifdef DEBUG_UPD +#define CHECK_BIT_STR( n ) ( n ) ? "\e[42;30m" : "\e[100;37m" +#define CHECK_BIT_RED( n ) ( n ) ? "\e[42;30m" : "\e[41;37m" +#define CHECK_4BIT_STR( b ) ( b ) & CHECK_BIT_STR( 0x20 ), \ + ( b ) & CHECK_BIT_STR( 0x10 ), \ + ( b ) & CHECK_BIT_STR( 0x08 ), \ + ( b ) & CHECK_BIT_STR( 0x04 ) + +#define CHECK_6BIT_STR( b ) ( b ) & CHECK_BIT_STR( 0x80 ), \ + ( b ) & CHECK_BIT_STR( 0x40 ), \ + ( b ) & CHECK_BIT_STR( 0x20 ), \ + ( b ) & CHECK_BIT_STR( 0x10 ), \ + ( b ) & CHECK_BIT_STR( 0x08 ), \ + ( b ) & CHECK_BIT_STR( 0x04 ) + +#define CHECK_8BIT_STR( b ) ( b ) & CHECK_BIT_STR( 0x80 ), \ + ( b ) & CHECK_BIT_STR( 0x40 ), \ + ( b ) & CHECK_BIT_STR( 0x20 ), \ + ( b ) & CHECK_BIT_STR( 0x10 ), \ + ( b ) & CHECK_BIT_STR( 0x08 ), \ + ( b ) & CHECK_BIT_STR( 0x04 ), \ + ( b ) & CHECK_BIT_STR( 0x02 ), \ + ( b ) & CHECK_BIT_STR( 0x01 ) +#endif /* #ifdef DEBUG_UPD */ + libspectrum_byte upd_fdc_read_status( upd_fdc *f ) { +#ifdef DEBUG_UPD + /* RQM DIO EXM CB D3B D2B D1B D0B */ + if( f ) { + static int last_status = -1; + static size_t num = 0; + if( last_status == f->main_status ) { + num++; + } else { + if( num ) + fprintf( stderr, "Main ST (0x%02x): %sRQM\e[0m %sDIO\e[0m %sEXM\e[0m %s CB\e[0m %sD3B\e[0m %sD2B\e[0m %sD1B\e[0m %sD0B\e[0m x%zu\n", last_status, + CHECK_8BIT_STR( last_status ), num ); + fprintf( stderr, "Main ST (0x%02x): %sRQM\e[0m %sDIO\e[0m %sEXM\e[0m %s CB\e[0m %sD3B\e[0m %sD2B\e[0m %sD1B\e[0m %sD0B\e[0m\n", f->main_status, + CHECK_8BIT_STR( f->main_status ) ); + last_status = f->main_status; + num = 0; + } + } +#endif /* #ifdef DEBUG_UPD */ + return f->main_status; } @@ -911,6 +983,10 @@ libspectrum_byte upd_fdc_read_data( upd_fdc *f ) { libspectrum_byte r; +#ifdef DEBUG_UPD + int state = f->state; + const char *t_str[] = { " NT", " AT", " IC", "RAT" }; +#endif /* #ifdef DEBUG_UPD */ fdd_t *d = f->current_drive; @@ -1000,15 +1076,54 @@ upd_fdc_read_data( upd_fdc *f ) if( f->intrq < UPD_INTRQ_READY ) f->intrq = UPD_INTRQ_NONE; } + +#ifdef DEBUG_UPD + if( state == UPD_FDC_STATE_RES ) { /* result */ + if( f->cmd->id == UPD_CMD_SENSE_DRIVE ) { /* sense drive -> ST3 */ + fprintf( stderr, "--- %s RESULT\nSTATUS3 (0x%02x): %sFLT\e[0m %s WP\e[0m %sRDY\e[0m %s T0\e[0m %s TS\e[0m %s HD\e[0m US: %d\n", debug_cmd_str[f->command_register & 0x1f], r, + CHECK_6BIT_STR( r ), r & 0x03 ); + } else if( f->cmd->id == UPD_CMD_SENSE_INT && f->cycle == 0 ) { /* ST0 PCN */ + fprintf( stderr, "--- %s RESULT\nSTATUS0 (0x%02x): TRM:%s%s\e[0m %s SE\e[0m %s EC\e[0m %s NR\e[0m %s HD\e[0m US: %d PCN:% 3d\n", debug_cmd_str[f->command_register & 0x1f], f->sense_int_res[0], + CHECK_BIT_RED( !( f->sense_int_res[0] & 0xc0 ) ), t_str[f->sense_int_res[0] >> 6], + CHECK_4BIT_STR( r ), f->sense_int_res[0] & 0x03, f->sense_int_res[1] ); + } else if( f->cmd->res_length == 7 && f->cycle == 0 ) { + fprintf( stderr, "--- %s RESULT\nSTATUS0 (0x%02x): TRM:%s%s\e[0m %s SE\e[0m %s EC\e[0m %s NR\e[0m %s HD\e[0m US: %d\n", debug_cmd_str[f->command_register & 0x1f], f->status_register[0], + CHECK_BIT_RED( !( f->status_register[0] & 0xc0 ) ), t_str[f->status_register[0] >> 6], + CHECK_4BIT_STR( r ), f->sense_int_res[0] & 0x03 ); + fprintf( stderr, "STATUS1 (0x%02x): %sEOC\e[0m %s---\e[0m %sIDE\e[0m %s OR\e[0m %s---\e[0m %s ND\e[0m %s NW\e[0m %s MA\e[0m\n", f->status_register[1], + CHECK_8BIT_STR( f->status_register[1] ) ); + fprintf( stderr, "STATUS2 (0x%02x): %s---\e[0m %s CM\e[0m %sDDE\e[0m %s WC\e[0m %s SH\e[0m %s SN\e[0m %s BC\e[0m %s MD\e[0m\n", f->status_register[2], + CHECK_8BIT_STR( f->status_register[2] ) ); + fprintf( stderr, "C H R N (....): CYL: %2d HEAD: %d REC:%3d LEN: %d\n", f->data_register[1], + f->data_register[2], f->data_register[3], f->data_register[4] ); + } + } +#endif /* #ifdef DEBUG_UPD */ + return r; } +#ifdef DEBUG_UPD +#define FDR( n ) f->data_register[n] +#define CHECK_CMD_STR( b ) ( b ) & CHECK_BIT_STR( 0x80 ), \ + ( b ) & CHECK_BIT_STR( 0x40 ), \ + ( b ) & CHECK_BIT_STR( 0x20 ) +#endif /* #ifdef DEBUG_UPD */ + void upd_fdc_write_data( upd_fdc *f, libspectrum_byte data ) { int i, terminated = 0; unsigned int u; fdd_t *d; +#ifdef DEBUG_UPD + static int cmd = 0; + + f->dbg_data_wr = 0; + if( f->cycle == 0 ) { + cmd = data; + } +#endif /* #ifdef DEBUG_UPD */ if( !( f->main_status & UPD_FDC_MAIN_DATAREQ ) || ( f->main_status & UPD_FDC_MAIN_DATA_READ ) ) @@ -1133,7 +1248,7 @@ upd_fdc_write_data( upd_fdc *f, libspectrum_byte data ) ( f->scan == UPD_SCAN_HI && d->data < data ) ) { f->status_register[2] |= UPD_FDC_ST2_SCAN_NOT_SAT; } - + if( f->data_offset == f->sector_length ) { /* read the CRC */ fdd_read_data( d ); crc_add( f, d ); fdd_read_data( d ); crc_add( f, d ); @@ -1191,6 +1306,10 @@ upd_fdc_write_data( upd_fdc *f, libspectrum_byte data ) f->main_status |= UPD_FDC_MAIN_EXECUTION; } +#ifdef DEBUG_UPD + f->dbg_data_wr = 1; +#endif + /* select current drive and head if needed */ if( f->cmd->id != UPD_CMD_SENSE_INT && f->cmd->id != UPD_CMD_SPECIFY && @@ -1385,4 +1504,34 @@ upd_fdc_write_data( upd_fdc *f, libspectrum_byte data ) } else { f->cycle++; } + +#ifdef DEBUG_UPD + if( f->dbg_data_wr ) { /* we already read all neccessery byte */ + if( f->cmd->cmd_length == 0 ) { /* 0 */ + fprintf( stderr, "\n--- %s (0x%02x) START\n", debug_cmd_str[f->command_register & 0x1f], cmd ); + } else if( f->cmd->cmd_length == 1 ) { /* HD, US */ + fprintf( stderr, "\n--- %s (0x%02x) START\n HD: %d US: %d\n", debug_cmd_str[f->command_register & 0x1f], cmd, ( data & 0x04 ) >> 2, data & 0x03 ); + } else if( f->cmd->id == UPD_CMD_SPECIFY ) { /* */ + fprintf( stderr, "\n--- %s (0x%02x) START\n SRT: %d HUT: %dms HLT: %dms NDMA: %d\n", debug_cmd_str[f->command_register & 0x1f], cmd, + FDR( 0 ) >> 4, FDR( 0 ) & 0x0f, + data >> 1, data & 1); + } else if( f->cmd->id == UPD_CMD_SEEK ) { /* */ + fprintf( stderr, "\n--- %s (0x%02x) START\n HD: %d US: %d NCN: %d\n", debug_cmd_str[f->command_register & 0x1f], cmd, + ( FDR( 0 ) & 0x04 ) >> 2, FDR( 0 ) & 0x03, data ); + } else if( f->cmd->cmd_length == 6 ) { /* HD, US */ + fprintf( stderr, "\n--- %s (0x%02x) START\n %sMT\e[0m %sMF\e[0m %sSK\e[0m HD: %d US: %d - N: %d SC: %d GPL: %d FILL: 0x%02x\n", debug_cmd_str[f->command_register & 0x1f], cmd, + CHECK_CMD_STR( f->command_register & 0x40 ), ( FDR( 0 ) & 0x04 ) >> 2, FDR( 0 ) & 0x03, + FDR( 1 ), FDR( 2 ), FDR( 3 ), data ); + } else if( f->cmd->cmd_length == 8 ) { + fprintf( stderr, "\n--- %s (0x%02x) START (%d)\n" + " %sMT\e[0m %sMF\e[0m %sSK\e[0m HD: %d US: %d\n" + " CYL: %2d HEAD: %d REC:%3d LEN: %d\n" + " EOT: %2d GPL: %2d DTL:%3d\n", debug_cmd_str[f->command_register & 0x1f], cmd, f->cycle, + CHECK_CMD_STR( f->command_register ), ( FDR( 0 ) & 0x04 ) >> 2, FDR( 0 ) & 0x03, + FDR( 1 ), FDR( 2 ), FDR( 3 ), FDR( 4 ), FDR( 5 ), FDR(6), data ); + } + } +#undef FDR +#endif /* #ifdef DEBUG_UPD */ + } diff --git a/peripherals/disk/upd_fdc.h b/peripherals/disk/upd_fdc.h index cffcf9d2..e14c0f30 100644 --- a/peripherals/disk/upd_fdc.h +++ b/peripherals/disk/upd_fdc.h @@ -33,6 +33,8 @@ #include "fdd.h" #include "fuse.h" +/* #define DEBUG_UPD 1 */ + typedef enum upd_type_t { UPD765A = 0, UPD765B, @@ -143,7 +145,7 @@ typedef struct upd_fdc { int seek_age[4]; /* order of overlapped seeks for 4 drive */ int rlen; /* expected record length */ upd_scan_t scan; /* SCAN type: eq/lo/hi */ - + upd_cmd_t *cmd; /* current command */ libspectrum_byte command_register; /* command register */ @@ -160,6 +162,9 @@ typedef struct upd_fdc { void ( *set_datarq ) ( struct upd_fdc *f ); void ( *reset_datarq ) ( struct upd_fdc *f ); +#ifdef DEBUG_UPD + int dbg_data_wr; +#endif } upd_fdc; void upd_fdc_init_events( void ); |