From 6b0cf308fc0a873168ace0486c7063228c32dc2c Mon Sep 17 00:00:00 2001 From: Matthew Harlum Date: Sun, 2 Jun 2024 09:45:24 +0000 Subject: [PATCH] Some code tidying --- ata.c | 23 ++++++++++++----------- device.h | 20 ++++++++++---------- driver.c | 13 ++++++++----- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ata.c b/ata.c index 60dce30..c564008 100644 --- a/ata.c +++ b/ata.c @@ -274,7 +274,7 @@ bool ata_init_unit(struct IDEUnit *unit) { for (int i=0; i<(8*NEXT_REG); i+=NEXT_REG) { // Check if the bus is floating (D7/6 pulled-up with resistors) - if ((i != ata_reg_devHead) && (*((volatile UBYTE *)unit->drive->data + i) & 0xC0) != 0xC0) { + if ((i != ata_reg_devHead) && (*((volatile UBYTE *)unit->drive + i) & 0xC0) != 0xC0) { dev_found = true; Trace("INIT: Unit base: %08lx; Drive base %08lx\n",unit, unit->drive); break; @@ -293,15 +293,15 @@ bool ata_init_unit(struct IDEUnit *unit) { if (ata_identify(unit,buf) == true) { Info("INIT: ATA Drive found!\n"); - unit->lba = ((*((UWORD *)buf + ata_identify_capabilities) & ata_capability_lba) != 0); - unit->cylinders = *((UWORD *)buf + ata_identify_cylinders); - unit->heads = *((UWORD *)buf + ata_identify_heads); - unit->sectorsPerTrack = *((UWORD *)buf + ata_identify_sectors); + unit->lba = (buf[ata_identify_capabilities] & ata_capability_lba) != 0; + unit->cylinders = buf[ata_identify_cylinders]; + unit->heads = buf[ata_identify_heads]; + unit->sectorsPerTrack = buf[ata_identify_sectors]; unit->blockSize = 512; - unit->logicalSectors = *((UWORD *)buf + ata_identify_logical_sectors+1) << 16 | *((UWORD *)buf + ata_identify_logical_sectors); + unit->logicalSectors = buf[ata_identify_logical_sectors+1] << 16 | buf[ata_identify_logical_sectors]; unit->blockShift = 0; unit->mediumPresent = true; - unit->multipleCount = (*((UWORD *)buf + ata_identify_multiple) & 0xFF); + unit->multipleCount = buf[ata_identify_multiple] & 0xFF; if (unit->multipleCount > 0 && (ata_set_multiple(unit,unit->multipleCount) == 0)) { unit->xferMultiple = true; @@ -311,16 +311,17 @@ bool ata_init_unit(struct IDEUnit *unit) { } // Support LBA-48 but only up to 2TB - if (((*((UWORD *)buf + ata_identify_features) & ata_feature_lba48) != 0) && unit->logicalSectors >= 0xFFFFFFF) { - if (*((UWORD *)buf + ata_identify_lba48_sectors + 2) > 0 || - *((UWORD *)buf + ata_identify_lba48_sectors + 3) > 0) { + if ((buf[ata_identify_features] & ata_feature_lba48) && unit->logicalSectors >= 0xFFFFFFF) { + if (buf[ata_identify_lba48_sectors + 2] > 0 || + buf[ata_identify_lba48_sectors + 3] > 0) { Info("INIT: Rejecting drive larger than 2TB\n"); return false; } unit->lba48 = true; Info("INIT: Drive supports LBA48 mode \n"); - unit->logicalSectors = (*((UWORD *)buf + ata_identify_lba48_sectors + 1) << 16 | *((UWORD *)buf + ata_identify_lba48_sectors)); + unit->logicalSectors = (buf[ata_identify_lba48_sectors + 1] << 16 | + buf[ata_identify_lba48_sectors]); unit->write_taskfile = &write_taskfile_lba48; } else if (unit->lba == true) { diff --git a/device.h b/device.h index 37b1da4..d58918d 100644 --- a/device.h +++ b/device.h @@ -53,19 +53,19 @@ struct IDEUnit { void (*write_unaligned)(void *, void *); volatile UBYTE *shadowDevHead; volatile void *changeInt; - volatile BOOL deferTUR; + volatile bool deferTUR; UBYTE unitNum; UBYTE channel; UBYTE deviceType; UBYTE last_error[6]; - BOOL primary; - BOOL present; - BOOL atapi; - BOOL mediumPresent; - BOOL mediumPresentPrev; - BOOL xferMultiple; - BOOL lba; - BOOL lba48; + bool primary; + bool present; + bool atapi; + bool mediumPresent; + bool mediumPresentPrev; + bool xferMultiple; + bool lba; + bool lba48; UWORD openCount; UWORD changeCount; UWORD heads; @@ -84,7 +84,7 @@ struct DeviceBase { struct Library *ExpansionBase; struct Task *ChangeTask; BPTR saved_seg_list; - BOOL isOpen; + bool isOpen; ULONG numUnits; ULONG highestUnit; UBYTE numTasks; diff --git a/driver.c b/driver.c index 3346d00..52de81f 100644 --- a/driver.c +++ b/driver.c @@ -892,7 +892,7 @@ static struct Library __attribute__((used)) * init(BPTR seg_list asm("a0")) ms->numUnits = 0; ms->SysBase = SysBase; - UWORD *idx = &ms->numUnits; + UWORD index = 0; #if CDBOOT BOOL CDBoot = FindCDFS(); #endif @@ -913,12 +913,15 @@ static struct Library __attribute__((used)) * init(BPTR seg_list asm("a0")) // If CDFS not resident don't bother adding the CDROM to the mountlist if (unit->deviceType == DG_CDROM && !CDBoot) continue; #endif - ms->Units[*idx].unitNum = unit->unitNum; - ms->Units[*idx].deviceType = unit->deviceType; - ms->Units[*idx].configDev = unit->cd; - *idx += 1; + ms->Units[index].unitNum = unit->unitNum; + ms->Units[index].deviceType = unit->deviceType; + ms->Units[index].configDev = unit->cd; + index++; } } + + ms->numUnits = index; + ReleaseSemaphore(&mydev->ulSem); if (ms->numUnits > 0) { MountDrive(ms);