pi1541/DiskCaddy.h

111 lines
2.6 KiB
C
Raw Normal View History

2018-05-20 04:53:34 +00:00
// Pi1541 - A Commodore 1541 disk drive emulator
// Copyright(C) 2018 Stephen White
//
// This file is part of Pi1541.
//
// Pi1541 is free software : you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pi1541 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pi1541. If not, see <http://www.gnu.org/licenses/>.
#ifndef DISKCADDY_H
#define DISKCADDY_H
#include <vector>
#include "DiskImage.h"
#include "Screen.h"
class DiskCaddy
{
public:
DiskCaddy()
: selectedIndex(0)
, screen(0)
{
}
void SetScreen(Screen* screen) { this->screen = screen; }
void Empty()
{
int index;
for (index = 0; index < (int)disks.size(); ++index)
{
disks[index].Close();
}
disks.clear();
selectedIndex = 0;
}
bool Insert(const FILINFO* fileInfo, bool readOnly);
DiskImage* GetCurrentDisk()
{
if (selectedIndex < disks.size())
return &disks[selectedIndex];
return 0;
}
DiskImage* NextDisk()
{
selectedIndex = (selectedIndex + 1) % (u32)disks.size();
return GetCurrentDisk();
}
DiskImage* PrevDisk()
{
selectedIndex = (selectedIndex - 1) % (u32)disks.size();
return GetCurrentDisk();
}
u32 GetNumberOfImages() const { return disks.size(); }
u32 GetSelectedIndex() const { return selectedIndex; }
DiskImage* GetImage(unsigned index) { return &disks[index]; }
DiskImage* SelectImage(unsigned index)
{
if (selectedIndex != index && index < disks.size())
{
selectedIndex = index;
return GetCurrentDisk();
}
return 0;
}
DiskImage* SelectFirstImage()
{
if (disks.size())
{
selectedIndex = 0;
return GetCurrentDisk();
}
return 0;
}
void Display();
bool Update();
private:
bool InsertD64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly);
bool InsertG64(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly);
bool InsertNIB(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly);
bool InsertNBZ(const FILINFO* fileInfo, unsigned char* diskImageData, unsigned size, bool readOnly);
void ShowSelectedImage(u32 index);
std::vector<DiskImage> disks;
u32 selectedIndex;
u32 oldCaddyIndex;
Screen* screen;
};
#endif