RASCSI/cpp/devices/cd_track.cpp
Daniel Markstedt 08194af424
Move C++ code into cpp/ dir (#941)
- Moved C++ code to cpp/ from src/raspberrypi
- Related updates to Makefile, easyinstall.sh, and the github build rules
- Removed the native X68k C code in src/x68k from the repo
2022-10-25 12:59:30 -07:00

126 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//---------------------------------------------------------------------------
//
// SCSI Target Emulator RaSCSI Reloaded
// for Raspberry Pi
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
//---------------------------------------------------------------------------
#include "cd_track.h"
#include <cassert>
void CDTrack::Init(int track, uint32_t first, uint32_t last)
{
assert(!valid);
assert(track >= 1);
assert(first < last);
// Set and enable track number
track_no = track;
valid = true;
// Remember LBA
first_lba = first;
last_lba = last;
}
void CDTrack::SetPath(bool cdda, string_view path)
{
assert(valid);
// CD-DA or data
audio = cdda;
// Remember the path
imgpath = path;
}
string CDTrack::GetPath() const
{
assert(valid);
return imgpath;
}
//---------------------------------------------------------------------------
//
// Gets the start of LBA
//
//---------------------------------------------------------------------------
uint32_t CDTrack::GetFirst() const
{
assert(valid);
assert(first_lba < last_lba);
return first_lba;
}
//---------------------------------------------------------------------------
//
// Get the end of LBA
//
//---------------------------------------------------------------------------
uint32_t CDTrack::GetLast() const
{
assert(valid);
assert(first_lba < last_lba);
return last_lba;
}
uint32_t CDTrack::GetBlocks() const
{
assert(valid);
assert(first_lba < last_lba);
// Calculate from start LBA and end LBA
return last_lba - first_lba + 1;
}
int CDTrack::GetTrackNo() const
{
assert(valid);
assert(track_no >= 1);
return track_no;
}
//---------------------------------------------------------------------------
//
// Is valid block
//
//---------------------------------------------------------------------------
bool CDTrack::IsValid(uint32_t lba) const
{
// false if the track itself is invalid
if (!valid) {
return false;
}
// If the block is BEFORE the first block
if (lba < first_lba) {
return false;
}
// If the block is AFTER the last block
if (last_lba < lba) {
return false;
}
// This track is valid
return true;
}
bool CDTrack::IsAudio() const
{
assert(valid);
return audio;
}