MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / ProDOS_DirGetFirstFreeEntryOffset

Function ProDOS_DirGetFirstFreeEntryOffset

source/ProDOS_FileSystem.h:363–395  ·  view source on GitHub ↗

@param nBase DiskImageOffset of directory returns DiskImageOffset ------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

361 // returns DiskImageOffset
362 // ------------------------------------------------------------------------
363 int ProDOS_DirGetFirstFreeEntryOffset ( uint8_t *pDiskBytes, ProDOS_VolumeHeader_t *pVolume, int nBase )
364 {
365 int iNextBlock;
366 int iPrevBlock;
367 int iOffset = nBase + 4; // Prev Block, Next Block
368
369 // Try to find a free file entry in this directory
370 do
371 {
372 iPrevBlock = ProDOS_Get16( pDiskBytes, nBase + 0 );
373 iNextBlock = ProDOS_Get16( pDiskBytes, nBase + 2 );
374
375 for( int iFile = 0; iFile < pVolume->entry_num; iFile++ )
376 {
377 ProDOS_FileHeader_t file;
378 ProDOS_GetFileHeader( pDiskBytes, iOffset, &file );
379
380 if (file.kind == PRODOS_KIND_DEL)
381 return iOffset;
382
383 if (file.len == 0)
384 return iOffset;
385
386 iOffset += pVolume->entry_len;
387 }
388
389 nBase = iNextBlock * PRODOS_BLOCK_SIZE;
390 iOffset = nBase + 4;
391
392 } while( iNextBlock );
393
394 return 0;
395 }
396
397// --- ProDOS Volume Functions ---
398

Callers 1

Util_ProDOS_AddFileFunction · 0.85

Calls 2

ProDOS_Get16Function · 0.85
ProDOS_GetFileHeaderFunction · 0.85

Tested by

no test coverage detected