@@ -190,13 +190,14 @@ typedef struct {
190190 unsigned char reply_mode; // 0=words, 1=bytes
191191 unsigned char reply_status;
192192 unsigned char half_sent;
193- unsigned char flash;
194193 int bufcnt;
195194 char *bufptr;
196195 char blkbuf[600 ];
197196} Interface;
198197Interface IF;
199198
199+ unsigned char IF_flash;
200+
200201// Cart ROM
201202char PakRom[0x4000 ];
202203
@@ -331,12 +332,12 @@ extern "C"
331332 // Return SDC status.
332333 __declspec (dllexport) void ModuleStatus(char *MyStatus)
333334 {
334- strncpy (MyStatus,Status,12 );
335+ strncpy (MyStatus,Status,16 );
335336 if (idle_ctr < 100 ) {
336337 idle_ctr++;
337338 } else {
338339 idle_ctr = 0 ;
339- strncpy (Status," SDC:Idle " , 12 );
340+ snprintf (Status,16 , " SDC:%d idle " ,CurrentBank );
340341 }
341342 return ;
342343 }
@@ -556,13 +557,7 @@ void SDCInit(void)
556557
557558 // Load SDC settings
558559 LoadConfig ();
559- if (!StartupComplete){
560- CurrentBank = StartupBank;
561- StartupComplete = true ;
562- } else if (CurrentBank != StartupBank) {
563- StartupComplete = false ;
564- }
565-
560+ CurrentBank = StartupBank;
566561 LoadRom ();
567562
568563 SetCurDir (" " ); // May be changed by ParseStartup()
@@ -724,7 +719,7 @@ bool LoadRom()
724719 int ctr = 0 ;
725720 f_ROM = fopen (RomName, " rb" );
726721 if (f_ROM == NULL ) {
727- _DLOG (" LoadRom '%s' failed errno %d \n " ,RomName,errno );
722+ _DLOG (" LoadRom '%s' failed %s \n " ,RomName,LastErrorTxt () );
728723 return false ;
729724 }
730725
@@ -804,7 +799,7 @@ void SDCWrite(unsigned char data,unsigned char port)
804799 break ;
805800 // Flash Data
806801 case 0x42 :
807- IF. flash = data;
802+ IF_flash = data;
808803 break ;
809804 // Flash Control
810805 case 0x43 :
@@ -886,7 +881,7 @@ unsigned char SDCRead(unsigned char port)
886881 switch (port) {
887882 // Flash control read is used by SDCDOS to detect the SDC
888883 case 0x43 :
889- rpy = CurrentBank | (IF. flash & 0xF8 );
884+ rpy = CurrentBank | (IF_flash & 0xF8 );
890885 break ;
891886 // Interface status
892887 case 0x48 :
@@ -1128,10 +1123,9 @@ void UpdateSD(void)
11281123// ----------------------------------------------------------------------
11291124void BankSelect (int data)
11301125{
1131- bool init = ((CurrentBank & 7 ) != (data & 7 ));
1132- _DLOG (" >>>> BankSelect %02x\n " ,data);
1126+ _DLOG (" BankSelect %d,%X\n " ,data,IF_flash);
11331127 CurrentBank = data & 7 ;
1134- if (init) SDCInit ();
1128+ LoadRom ();
11351129}
11361130
11371131// ----------------------------------------------------------------------
@@ -1196,7 +1190,7 @@ bool ReadDrive(unsigned char cmdcode, unsigned int lsn)
11961190 return false ;
11971191 }
11981192
1199- sprintf (Status," SDC:Rd %d, %d" ,drive,lsn);
1193+ snprintf (Status,16 , " SDC:%d Rd %d,%d" ,CurrentBank ,drive,lsn);
12001194 LoadReply (buf,cnt);
12011195 return true ;
12021196}
@@ -1259,7 +1253,7 @@ void WriteSector(void)
12591253 DWORD cnt = 0 ;
12601254 int drive = IF.cmdcode & 1 ;
12611255 unsigned int lsn = (IF.param1 << 16 ) + (IF.param2 << 8 ) + IF.param3 ;
1262- sprintf (Status," SDC:Wr %d, %d" ,drive,lsn);
1256+ snprintf (Status,16 , " SDC:%d Wr %d,%d" ,CurrentBank ,drive,lsn);
12631257
12641258 if (Disk[drive].hFile == NULL ) {
12651259 IF.status = STA_FAIL;
@@ -1524,6 +1518,7 @@ bool MountDisk (int drive, const char * path)
15241518bool MountNext (int drive)
15251519{
15261520 if (FindNextFile (hFind,&dFound) == 0 ) {
1521+ _DLOG (" MountNext no more\n " );
15271522 FindClose (hFind);
15281523 hFind = INVALID_HANDLE_VALUE;
15291524 return false ;
@@ -1532,6 +1527,7 @@ bool MountNext (int drive)
15321527 // Open next image found on the drive
15331528 if (!OpenFound (drive)) {
15341529 memset ((void *) &Disk[drive],0 ,sizeof (_Disk));
1530+ _DLOG (" MountNext can't open next\n " );
15351531 return false ;
15361532 }
15371533
0 commit comments