Skip to content

Commit

Permalink
Some code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
LIV2 committed Jun 2, 2024
1 parent 5c5a36b commit 6b0cf30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
23 changes: 12 additions & 11 deletions ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 6b0cf30

Please sign in to comment.