[PATCH] Split SCSI init/uninit handling from ACSI init/uninit

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


These changes fix following issues:
- TOS booting from A: although SCSI HD drive was enabled
- Internal partition count being wrong after either
  ACSI or SCSI HD settings have been changed, due to
  SCSI drives not being deducted on SCSI UnInit()
  (drive count would be corrected on next emulation
  reset as that resets also drive count)
- Fix ACSI/SCSI/IDE comments to use plural form as
  nowadays all of them can have multiple drives/images
---
 doc/release-notes.txt  |  1 +
 src/change.c           | 30 ++++++++++++++++++++----------
 src/floppy.c           |  3 ++-
 src/gemdos.c           |  8 ++++++--
 src/hdc.c              | 19 ++++---------------
 src/includes/ncr5380.h |  5 ++++-
 src/main.c             |  5 ++++-
 src/ncr5380.c          | 31 ++++++++++++++++++++++++-------
 8 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/doc/release-notes.txt b/doc/release-notes.txt
index 29c10d4c..f389dbaa 100644
--- a/doc/release-notes.txt
+++ b/doc/release-notes.txt
@@ -63,6 +63,7 @@ Emulator:
 - Add --lilo debug option for more convenient m68k Linux loading
   - Support config file values with '=' in them
 - Fix: run-time IDE byte swap change requires IDE re-init
+- Fix: TOS booting from A: although SCSI drive was enabled
 - GEMDOS HD emulation:
   - Support FASTLOAD program flag with GEMDOS HD
   - GEMDOS HD emulation cartridge assembly functionality is moved almost
diff --git a/src/change.c b/src/change.c
index b69117cf..903fc913 100644
--- a/src/change.c
+++ b/src/change.c
@@ -28,6 +28,7 @@ const char Change_fileid[] = "Hatari change.c : " __DATE__ " " __TIME__;
 #include "keymap.h"
 #include "m68000.h"
 #include "midi.h"
+#include "ncr5380.h"
 #include "options.h"
 #include "printer.h"
 #include "reset.h"
@@ -182,6 +183,7 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 {
 	bool NeedReset;
 	bool bReInitGemdosDrive = false;
+	bool bReInitScsiEmu = false;
 	bool bReInitHdcEmu = false;
 	bool bReInitIDEEmu = false;
 	bool bReInitIoMem = false;
@@ -294,7 +296,7 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 		bReInitGemdosDrive = true;
 	}
 
-	/* Did change ACSI image? */
+	/* Did change ACSI images? */
 	for (i = 0; i < MAX_ACSI_DEVS; i++)
 	{
 		if (changed->Acsi[i].bUseDevice != current->Acsi[i].bUseDevice
@@ -305,7 +307,10 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 			bReInitHdcEmu = true;
 		}
 	}
-	/* Did change SCSI image? */
+	if (bReInitHdcEmu)
+		HDC_UnInit();
+
+	/* Did change SCSI images? */
 	for (i = 0; i < MAX_SCSI_DEVS; i++)
 	{
 		if (changed->Scsi[i].bUseDevice != current->Scsi[i].bUseDevice
@@ -313,13 +318,13 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 		        && changed->Scsi[i].bUseDevice))
 		{
 			Dprintf("- SCSI image %i>\n", i);
-			bReInitHdcEmu = true;
+			bReInitScsiEmu = true;
 		}
 	}
-	if (bReInitHdcEmu)
-		HDC_UnInit();
+	if (bReInitScsiEmu)
+		Ncr5380_UnInit();
 
-	/* Did change IDE HD image or its settings? */
+	/* Did change IDE HD images or their settings? */
 	for (i = 0; i < MAX_IDE_DEVS; i++)
 	{
 		if (changed->Ide[i].bUseDevice != current->Ide[i].bUseDevice
@@ -399,14 +404,19 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 		Keymap_LoadRemapFile(ConfigureParams.Keyboard.szMappingFileName);
 	}
 
-	/* Mount a new ACSI/SCSI HD images: */
+	/* Mount new ACSI HD images: */
 	if (bReInitHdcEmu)
 	{
-		Dprintf("- HD<\n");
+		Dprintf("- ACSI<\n");
 		HDC_Init();
 	}
-
-	/* Mount a new IDE HD images: */
+	/* Mount new SCSI HD images: */
+	if (bReInitScsiEmu)
+	{
+		Dprintf("- SCSI<\n");
+		Ncr5380_Init();
+	}
+	/* Mount new IDE HD images: */
 	if (bReInitIDEEmu && Ide_IsAvailable())
 	{
 		Dprintf("- IDE<\n");
diff --git a/src/floppy.c b/src/floppy.c
index 1c6c54a6..4485e8d2 100644
--- a/src/floppy.c
+++ b/src/floppy.c
@@ -33,6 +33,7 @@ const char Floppy_fileid[] = "Hatari floppy.c : " __DATE__ " " __TIME__;
 #include "floppy.h"
 #include "gemdos.h"
 #include "hdc.h"
+#include "ncr5380.h"
 #include "log.h"
 #include "memorySnapShot.h"
 #include "st.h"
@@ -174,7 +175,7 @@ void Floppy_GetBootDrive(void)
 	if (!ConfigureParams.HardDisk.bBootFromHardDisk)
 		return;
 
-	if (bAcsiEmuOn || ConfigureParams.Ide[0].bUseDevice)
+	if (bAcsiEmuOn || bScsiEmuOn || ConfigureParams.Ide[0].bUseDevice)
 	{
 		nBootDrive = 2;  /* Drive C */
 	}
diff --git a/src/gemdos.c b/src/gemdos.c
index d52815ba..a728a76f 100644
--- a/src/gemdos.c
+++ b/src/gemdos.c
@@ -49,6 +49,7 @@ const char Gemdos_fileid[] = "Hatari gemdos.c : " __DATE__ " " __TIME__;
 #include "ide.h"
 #include "inffile.h"
 #include "hdc.h"
+#include "ncr5380.h"
 #include "gemdos.h"
 #include "gemdos_defines.h"
 #include "log.h"
@@ -699,12 +700,15 @@ void GemDOS_InitDrives(void)
 		}
 	}
 
-	ImagePartitions = nAcsiPartitions + nIDEPartitions;
+	ImagePartitions = nAcsiPartitions + nScsiPartitions + nIDEPartitions;
 	if (ConfigureParams.HardDisk.nGemdosDrive == DRIVE_SKIP)
 		SkipPartitions = ImagePartitions;
 	else
 		SkipPartitions = ConfigureParams.HardDisk.nGemdosDrive;
 
+	Log_Printf(LOG_DEBUG, "ACSI: %d, SCSI: %d, IDE: %d - GEMDOS skipping %d partitions.\n",
+		   nAcsiPartitions, nScsiPartitions, nIDEPartitions, SkipPartitions);
+
 	/* Now initialize all available drives */
 	for(i = 0; i < nMaxDrives; i++)
 	{
@@ -752,7 +756,7 @@ void GemDOS_InitDrives(void)
 			 *  table(s) match each other).
 			 */
 			if (i < ImagePartitions)
-				Log_Printf(LOG_WARN, "GEMDOS HD drive %c: (may) override ACSI/IDE image partitions!\n", 'A'+DriveNumber);
+				Log_Printf(LOG_WARN, "GEMDOS HD drive %c: (may) override ACSI/SCSI/IDE image partitions!\n", 'A'+DriveNumber);
 		}
 		else
 		{
diff --git a/src/hdc.c b/src/hdc.c
index ccdf6679..5e823c10 100644
--- a/src/hdc.c
+++ b/src/hdc.c
@@ -853,7 +853,7 @@ int HDC_InitDevice(SCSI_DEV *dev, char *filename, unsigned long blockSize)
 }
 
 /**
- * Open the disk image file, set partitions.
+ * Open the disk image files, set partitions.
  */
 bool HDC_Init(void)
 {
@@ -876,20 +876,12 @@ bool HDC_Init(void)
 		if (!ConfigureParams.Acsi[i].bUseDevice)
 			continue;
 		if (HDC_InitDevice(&AcsiBus.devs[i], ConfigureParams.Acsi[i].sDeviceFile, ConfigureParams.Acsi[i].nBlockSize) == 0)
-		{
-			bAcsiEmuOn = true;
 			nAcsiPartitions += HDC_PartitionCount(AcsiBus.devs[i].image_file, TRACE_SCSI_CMD, NULL);
-		}
 	}
-
-	/* add SCSI partition count to ACSI ones
-	 * to support GEMDOS HD emu partition skipping
-	 */
-	nAcsiPartitions += Ncr5380_Init();
-
 	/* set total number of partitions */
 	nNumDrives += nAcsiPartitions;
-
+	if (nAcsiPartitions)
+		bAcsiEmuOn = true;
 	return bAcsiEmuOn;
 }
 
@@ -915,10 +907,7 @@ void HDC_UnInit(void)
 	free(AcsiBus.buffer);
 	AcsiBus.buffer = NULL;
 
-	Ncr5380_UnInit();
-
-	if (bAcsiEmuOn)
-		nNumDrives -= nAcsiPartitions;
+	nNumDrives -= nAcsiPartitions;
 	nAcsiPartitions = 0;
 	bAcsiEmuOn = false;
 }
diff --git a/src/includes/ncr5380.h b/src/includes/ncr5380.h
index 1fc666c3..da3d2ab2 100644
--- a/src/includes/ncr5380.h
+++ b/src/includes/ncr5380.h
@@ -8,7 +8,10 @@
 #ifndef NCR5380_H
 #define NCR5380_H
 
-int Ncr5380_Init(void);
+extern int nScsiPartitions;
+extern bool bScsiEmuOn;
+
+bool Ncr5380_Init(void);
 void Ncr5380_UnInit(void);
 void Ncr5380_Reset(void);
 void Ncr5380_WriteByte(int addr, Uint8 byte);
diff --git a/src/main.c b/src/main.c
index aa88db25..3348f110 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@ const char Main_fileid[] = "Hatari main.c : " __DATE__ " " __TIME__;
 #include "m68000.h"
 #include "memorySnapShot.h"
 #include "midi.h"
+#include "ncr5380.h"
 #include "nvram.h"
 #include "paths.h"
 #include "printer.h"
@@ -790,11 +791,12 @@ static void Main_Init(void)
 
 	/* Init HD emulation */
 	HDC_Init();
+	Ncr5380_Init();
 	Ide_Init();
 	GemDOS_Init();
 	if (ConfigureParams.HardDisk.bUseHardDiskDirectories)
 	{
-		/* uses variables set by HDC_Init()! */
+		/* uses variables set by HDC_Init/Ncr5380_Init/Ide_Init */
 		GemDOS_InitDrives();
 	}
 
@@ -830,6 +832,7 @@ static void Main_UnInit(void)
 	Screen_ReturnFromFullScreen();
 	Floppy_UnInit();
 	HDC_UnInit();
+	Ncr5380_UnInit();
 	Midi_UnInit();
 	SCC_UnInit();
 	RS232_UnInit();
diff --git a/src/ncr5380.c b/src/ncr5380.c
index caf30119..44e6eaf7 100644
--- a/src/ncr5380.c
+++ b/src/ncr5380.c
@@ -28,9 +28,13 @@ const char NCR5380_fileid[] = "Hatari ncr5380.c";
 #include "ncr5380.h"
 #include "stMemory.h"
 #include "newcpu.h"
+#include "tos.h"
 
 #define WITH_NCR5380 1
 
+int nScsiPartitions;
+bool bScsiEmuOn;
+
 static SCSI_CTRLR ScsiBus;
 
 #define MAX_TOTAL_SCSI_DEVICES 8
@@ -1008,12 +1012,16 @@ void ncr5380_bput(struct soft_scsi *scsi, int reg, uae_u8 v)
 /* ***** Hatari glue code below ***** */
 
 /**
- * return number of identified partitions on existing SCSI images
+ * Open the disk image file, set partitions count.
+ * Return true if there are any.
  */
-int Ncr5380_Init(void)
+bool Ncr5380_Init(void)
 {
 #if WITH_NCR5380
-	int i, partitions = 0;
+	int i;
+
+	nScsiPartitions = 0;
+	bScsiEmuOn = false;
 
 	memset(&ScsiBus, 0, sizeof(ScsiBus));
 	ScsiBus.typestr = "SCSI";
@@ -1029,14 +1037,19 @@ int Ncr5380_Init(void)
 		if (!ConfigureParams.Scsi[i].bUseDevice)
 			continue;
 		if (HDC_InitDevice(&ScsiBus.devs[i], ConfigureParams.Scsi[i].sDeviceFile, ConfigureParams.Scsi[i].nBlockSize) == 0)
-			partitions += HDC_PartitionCount(ScsiBus.devs[i].image_file, TRACE_SCSI_CMD, NULL);
+			nScsiPartitions += HDC_PartitionCount(ScsiBus.devs[i].image_file, TRACE_SCSI_CMD, NULL);
 	}
-	return partitions;
-#else
-	return 0;
+	nNumDrives += nScsiPartitions;
+	if (nScsiPartitions)
+		bScsiEmuOn = true;
 #endif
+	return bScsiEmuOn;
 }
 
+/**
+ * Ncr5380_UnInit - close image files and free resources
+ *
+ */
 void Ncr5380_UnInit(void)
 {
 #if WITH_NCR5380
@@ -1053,6 +1066,10 @@ void Ncr5380_UnInit(void)
 	}
 	free(ScsiBus.buffer);
 	ScsiBus.buffer = NULL;
+
+	nNumDrives -= nScsiPartitions;
+	nScsiPartitions = 0;
+	bScsiEmuOn = false;
 #endif
 }
 
-- 
2.20.1


--------------4CCFA4628AD4E81E38D8EA42--



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/