Feature baremetal removal (#140)

* Removed all BAREMETAL ifdefs

* Cleaned up subfolders

* Fixed regression

* Re-added underscores

* Fixed merge conflicts

* Assume RASCSI is always defined

* Fixed mege issue

* Re-added result message

* Fix typo

Co-authored-by: akuker <34318535+akuker@users.noreply.github.com>
This commit is contained in:
uweseimet 2021-07-20 15:32:44 +02:00 committed by GitHub
parent 0032ce5010
commit 3c5a0003a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 22 additions and 1907 deletions

View File

@ -31,19 +31,10 @@
// Constructor
//
//---------------------------------------------------------------------------
#ifdef RASCSI
SASIDEV::SASIDEV()
#else
SASIDEV::SASIDEV(Device *dev)
#endif // RASCSI
{
int i;
#ifndef RASCSI
// Remember host device
host = dev;
#endif // RASCSI
// Work initialization
ctrl.phase = BUS::busfree;
ctrl.m_scsi_id = UNKNOWN_SCSI_ID;
@ -94,9 +85,7 @@ void FASTCALL SASIDEV::Reset()
ctrl.phase = BUS::busfree;
ctrl.status = 0x00;
ctrl.message = 0x00;
#ifdef RASCSI
ctrl.execstart = 0;
#endif // RASCSI
memset(ctrl.buffer, 0x00, ctrl.bufsize);
ctrl.blocks = 0;
ctrl.next = 0;
@ -111,80 +100,6 @@ void FASTCALL SASIDEV::Reset()
}
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Save
//
//---------------------------------------------------------------------------
BOOL FASTCALL SASIDEV::Save(Fileio *fio, int /*ver*/)
{
ASSERT(fio);
// Save size
DWORD sz = 2120;
if (!fio->Write(&sz, sizeof(sz))) {
return FALSE;
}
// Save entity
PROP_EXPORT(fio, ctrl.phase);
PROP_EXPORT(fio, ctrl.id);
PROP_EXPORT(fio, ctrl.cmd);
PROP_EXPORT(fio, ctrl.status);
PROP_EXPORT(fio, ctrl.message);
if (!fio->Write(ctrl.buffer, 0x800)) {
return FALSE;
}
PROP_EXPORT(fio, ctrl.blocks);
PROP_EXPORT(fio, ctrl.next);
PROP_EXPORT(fio, ctrl.offset);
PROP_EXPORT(fio, ctrl.length);
return TRUE;
}
//---------------------------------------------------------------------------
//
// Load
//
//---------------------------------------------------------------------------
BOOL FASTCALL SASIDEV::Load(Fileio *fio, int ver)
{
ASSERT(fio);
// Not saved before version 3.11
if (ver <= 0x0311) {
return TRUE;
}
// Load size and check if the size matches
DWORD sz;
if (!fio->Read(&sz, sizeof(sz))) {
return FALSE;
}
if (sz != 2120) {
return FALSE;
}
// Load the entity
PROP_IMPORT(fio, ctrl.phase);
PROP_IMPORT(fio, ctrl.id);
PROP_IMPORT(fio, ctrl.cmd);
PROP_IMPORT(fio, ctrl.status);
PROP_IMPORT(fio, ctrl.message);
if (!fio->Read(ctrl.buffer, 0x800)) {
return FALSE;
}
PROP_IMPORT(fio, ctrl.blocks);
PROP_IMPORT(fio, ctrl.next);
PROP_IMPORT(fio, ctrl.offset);
PROP_IMPORT(fio, ctrl.length);
return TRUE;
}
#endif // RASCSI
//---------------------------------------------------------------------------
//
// Connect the controller
@ -411,14 +326,11 @@ void FASTCALL SASIDEV::Selection()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Command()
{
#ifdef RASCSI
int count;
int i;
#endif // RASCSI
// Phase change
if (ctrl.phase != BUS::command) {
LOGTRACE("%s Command Phase", __PRETTY_FUNCTION__);
// Phase Setting
@ -434,7 +346,6 @@ void FASTCALL SASIDEV::Command()
ctrl.length = 6;
ctrl.blocks = 1;
#ifdef RASCSI
// Command reception handshake (10 bytes are automatically received at the first command)
count = ctrl.bus->CommandHandShake(ctrl.buffer);
@ -473,26 +384,7 @@ void FASTCALL SASIDEV::Command()
Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_LUN);
}
#else
// Request the command
ctrl.bus->SetREQ(TRUE);
return;
#endif // RASCSI
}
#ifndef RASCSI
// Requesting
if (ctrl.bus->GetREQ()) {
// Sent by the initiator
if (ctrl.bus->GetACK()) {
Receive();
}
} else {
// Request the initator to
if (!ctrl.bus->GetACK()) {
ReceiveNext();
}
}
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -510,9 +402,7 @@ void FASTCALL SASIDEV::Execute()
// Initialization for data transfer
ctrl.offset = 0;
ctrl.blocks = 1;
#ifdef RASCSI
ctrl.execstart = SysTimer::GetTimerLow();
#endif // RASCSI
// Discard pending sense data from the previous command if the current command is not REQUEST SENSE
if ((SASIDEV::scsi_command)ctrl.cmd[0] != eCmdRequestSense) {
@ -603,15 +493,11 @@ void FASTCALL SASIDEV::Execute()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Status()
{
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
// Phase change
if (ctrl.phase != BUS::status) {
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -623,7 +509,6 @@ void FASTCALL SASIDEV::Status()
} else {
SysTimer::SleepUsec(5);
}
#endif // RASCSI
// Phase Setting
ctrl.phase = BUS::status;
@ -639,34 +524,13 @@ void FASTCALL SASIDEV::Status()
ctrl.blocks = 1;
ctrl.buffer[0] = (BYTE)ctrl.status;
#ifndef RASCSI
// Request status
ctrl.bus->SetDAT(ctrl.buffer[0]);
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
LOGTRACE( "%s Status Phase $%02X",__PRETTY_FUNCTION__, (unsigned int)ctrl.status);
return;
}
#ifdef RASCSI
// Send
Send();
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Initiator received
if (ctrl.bus->GetACK()) {
SendNext();
}
} else {
// Initiator requests next
if (!ctrl.bus->GetACK()) {
Send();
}
}
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -707,17 +571,13 @@ void FASTCALL SASIDEV::MsgIn()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::DataIn()
{
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
ASSERT(ctrl.length >= 0);
// Phase change
if (ctrl.phase != BUS::datain) {
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -727,7 +587,6 @@ void FASTCALL SASIDEV::DataIn()
}
ctrl.execstart = 0;
}
#endif // RASCSI
// If the length is 0, go to the status phase
if (ctrl.length == 0) {
@ -763,17 +622,13 @@ void FASTCALL SASIDEV::DataIn()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::DataOut()
{
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
ASSERT(ctrl.length >= 0);
// Phase change
if (ctrl.phase != BUS::dataout) {
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -783,7 +638,6 @@ void FASTCALL SASIDEV::DataOut()
}
ctrl.execstart = 0;
}
#endif // RASCSI
// If the length is 0, go to the status phase
if (ctrl.length == 0) {
@ -805,31 +659,11 @@ void FASTCALL SASIDEV::DataOut()
ASSERT(ctrl.length > 0);
ASSERT(ctrl.blocks > 0);
ctrl.offset = 0;
#ifndef RASCSI
// Request data
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
return;
}
#ifdef RASCSI
// Receive
Receive();
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Sent by the initiator
if (ctrl.bus->GetACK()) {
Receive();
}
} else {
// Request the initator to
if (!ctrl.bus->GetACK()) {
ReceiveNext();
}
}
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -1292,9 +1126,7 @@ void FASTCALL SASIDEV::CmdInvalid()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Send()
{
#ifdef RASCSI
int len;
#endif // RASCSI
BOOL result;
ASSERT(!ctrl.bus->GetREQ());
@ -1332,9 +1164,6 @@ void FASTCALL SASIDEV::Send()
result = XferIn(ctrl.buffer);
LOGTRACE("%s xfer in: %d",__PRETTY_FUNCTION__, result);
LOGTRACE("%s processing after data collection", __PRETTY_FUNCTION__);
#ifndef RASCSI
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
#endif // RASCSI
}
}
@ -1349,10 +1178,6 @@ void FASTCALL SASIDEV::Send()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
return;
}
@ -1386,29 +1211,6 @@ void FASTCALL SASIDEV::Send()
}
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Continue sending data
//
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::SendNext()
{
// Req is up
ASSERT(ctrl.bus->GetREQ());
ASSERT(ctrl.bus->GetIO());
// Signal line operated by the target
ctrl.bus->SetREQ(FALSE);
// If there is data in the buffer, set it first.
if (ctrl.length > 1) {
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset + 1]);
}
}
#endif // RASCSI
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Receive data
@ -1416,70 +1218,13 @@ void FASTCALL SASIDEV::SendNext()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Receive()
{
// Req is up
ASSERT(ctrl.bus->GetREQ());
ASSERT(!ctrl.bus->GetIO());
// Get data
DWORD data = (DWORD)ctrl.bus->GetDAT();
// Signal line operated by the target
ctrl.bus->SetREQ(FALSE);
switch (ctrl.phase) {
// Command phase
case BUS::command:
ctrl.cmd[ctrl.offset] = data;
LOGTRACE( "%s Command phase $%02X", __PRETTY_FUNCTION__, data);
// Set the length again with the first data (offset 0)
if (ctrl.offset == 0) {
if (ctrl.cmd[0] >= 0x20 && ctrl.cmd[0] <= 0x7D) {
// 10 byte CDB
ctrl.length = 10;
}
}
break;
// Data out phase
case BUS::dataout:
ctrl.buffer[ctrl.offset] = (BYTE)data;
break;
// Other (impossible)
default:
ASSERT(FALSE);
break;
}
}
#endif // RASCSI
#ifdef RASCSI
//---------------------------------------------------------------------------
//
// Receive data
//
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Receive()
#else
//---------------------------------------------------------------------------
//
// Continue receiving data
//
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::ReceiveNext()
#endif // RASCSI
{
#ifdef RASCSI
int len;
#endif // RASCSI
BOOL result;
// REQ is low
ASSERT(!ctrl.bus->GetREQ());
ASSERT(!ctrl.bus->GetIO());
#ifdef RASCSI
// Length != 0 if received
if (ctrl.length != 0) {
// Receive
@ -1502,19 +1247,6 @@ void FASTCALL SASIDEV::ReceiveNext()
{
LOGDEBUG("%s ctrl.length was 0", __PRETTY_FUNCTION__);
}
#else
// Offset and Length
ASSERT(ctrl.length >= 1);
ctrl.offset++;
ctrl.length--;
// If length != 0, set req again
if (ctrl.length != 0) {
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
// Remove the control block and initialize the result
ctrl.blocks--;
@ -1541,30 +1273,11 @@ void FASTCALL SASIDEV::ReceiveNext()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
return;
}
// Move to the next phase
switch (ctrl.phase) {
#ifndef RASCSI
// Command phase
case BUS::command:
// Execution Phase
try {
Execute();
}
catch (const lunexception& e) {
LOGINFO("%s unsupported LUN %d", __PRETTY_FUNCTION__, (int)e.getlun());
// LOGICAL UNIT NOT SUPPORTED
Error(SENSE_KEY_ILLEGAL_REQUEST, ASC_INVALID_LUN);
}
break;
#endif // RASCSI
// Data out phase
case BUS::dataout:
LOGTRACE("%s transitioning to FlushUnit()",__PRETTY_FUNCTION__);

View File

@ -106,13 +106,11 @@ public:
const int DEFAULT_BUFFER_SIZE = 0x800;
const int DAYNAPORT_BUFFER_SIZE = 0x1000000;
#ifdef RASCSI
// For timing adjustments
enum {
min_exec_time_sasi = 100, // SASI BOOT/FORMAT 30:NG 35:OK
min_exec_time_scsi = 50
};
#endif // RASCSI
// Internal data definition
typedef struct {
@ -126,10 +124,8 @@ public:
DWORD status; // Status data
DWORD message; // Message data
#ifdef RASCSI
// Run
DWORD execstart; // Execution start time
#endif // RASCSI
// Transfer
BYTE *buffer; // Transfer data buffer
@ -149,21 +145,10 @@ public:
public:
// Basic Functions
#ifdef RASCSI
SASIDEV();
#else
SASIDEV(Device *dev); // Constructor
#endif //RASCSI
virtual ~SASIDEV(); // Destructor
virtual void FASTCALL Reset(); // Device Reset
#ifndef RASCSI
virtual BOOL FASTCALL Save(Fileio *fio, int ver); // Save
virtual BOOL FASTCALL Load(Fileio *fio, int ver); // Load
#endif //RASCSI
// External API
virtual BUS::phase_t FASTCALL Process(); // Run
@ -219,16 +204,8 @@ protected:
// データ転送
virtual void FASTCALL Send(); // Send data
#ifndef RASCSI
virtual void FASTCALL SendNext(); // Continue sending data
#endif // RASCSI
virtual void FASTCALL Receive(); // Receive data
#ifndef RASCSI
virtual void FASTCALL ReceiveNext(); // Continue receiving data
#endif // RASCSI
BOOL FASTCALL XferIn(BYTE* buf); // Data transfer IN
BOOL FASTCALL XferOut(BOOL cont); // Data transfer OUT
@ -238,8 +215,5 @@ protected:
DWORD FASTCALL GetLun(); // Get the validated LUN
protected:
#ifndef RASCSI
Device *host; // Host device
#endif // RASCSI
ctrl_t ctrl; // Internal data
};

View File

@ -31,11 +31,7 @@
// Constructor
//
//---------------------------------------------------------------------------
#ifdef RASCSI
SCSIDEV::SCSIDEV() : SASIDEV()
#else
SCSIDEV::SCSIDEV(Device *dev) : SASIDEV(dev)
#endif
{
// Synchronous transfer work initialization
scsi.syncenable = FALSE;
@ -292,9 +288,7 @@ void FASTCALL SCSIDEV::Execute()
// Initialization for data transfer
ctrl.offset = 0;
ctrl.blocks = 1;
#ifdef RASCSI
ctrl.execstart = SysTimer::GetTimerLow();
#endif // RASCSI
// If the command is valid it must be contained in the command map
if (!scsi_commands.count(static_cast<scsi_command>(ctrl.cmd[0]))) {
@ -351,10 +345,6 @@ void FASTCALL SCSIDEV::MsgOut()
ctrl.length = 1;
ctrl.blocks = 1;
#ifndef RASCSI
// Request message
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
return;
}
@ -1277,15 +1267,12 @@ void FASTCALL SCSIDEV::CmdEnableInterface()
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::Send()
{
#ifdef RASCSI
int len;
#endif // RASCSI
BOOL result;
ASSERT(!ctrl.bus->GetREQ());
ASSERT(ctrl.bus->GetIO());
#ifdef RASCSI
//if Length! = 0, send
if (ctrl.length != 0) {
LOGTRACE("%s sending handhake with offset %lu, length %lu", __PRETTY_FUNCTION__, ctrl.offset, ctrl.length);
@ -1314,20 +1301,6 @@ void FASTCALL SCSIDEV::Send()
ctrl.length = 0;
return;
}
#else
// offset and length
ASSERT(ctrl.length >= 1);
ctrl.offset++;
ctrl.length--;
// Immediately after ACK is asserted, if the data has been
// set by SendNext, raise the request
if (ctrl.length != 0) {
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
// Block subtraction, result initialization
ctrl.blocks--;
@ -1339,9 +1312,6 @@ void FASTCALL SCSIDEV::Send()
// set next buffer (set offset, length)
result = XferIn(ctrl.buffer);
LOGTRACE("%s processing after data collection. Blocks: %lu", __PRETTY_FUNCTION__, ctrl.blocks);
#ifndef RASCSI
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
#endif // RASCSI
}
}
@ -1356,10 +1326,6 @@ void FASTCALL SCSIDEV::Send()
LOGTRACE("%s Continuing to send. blocks = %lu", __PRETTY_FUNCTION__, ctrl.blocks);
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
return;
}
@ -1403,28 +1369,6 @@ void FASTCALL SCSIDEV::Send()
}
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Continue data transmission.....
//
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::SendNext()
{
// REQ is up
ASSERT(ctrl.bus->GetREQ());
ASSERT(ctrl.bus->GetIO());
// Signal line operated by the target
ctrl.bus->SetREQ(FALSE);
// If there is data in the buffer, set it first
if (ctrl.length > 1) {
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset + 1]);
}
}
#endif // RASCSI
//---------------------------------------------------------------------------
//
// Receive Data

View File

@ -109,13 +109,7 @@ private:
void FASTCALL CmdEnableInterface(); // DaynaPort specific command
// データ転送
void FASTCALL Send(); // Send data
#ifndef RASCSI
void FASTCALL SendNext(); // Continue sending data
#endif // RASCSI
void FASTCALL Receive(); // Receive data
#ifndef RASCSI
void FASTCALL ReceiveNext(); // Continue receiving data
#endif // RASCSI
BOOL FASTCALL XferMsg(DWORD msg); // Data transfer message
scsi_t scsi; // Internal data

View File

@ -24,36 +24,6 @@
#include "filepath.h"
#include "cfilesystem.h"
#ifdef BAREMETAL
//---------------------------------------------------------------------------
//
// FatFs用タイムスタンプ
//
//---------------------------------------------------------------------------
#define FF_NORTC_HOUR 6
#define FF_NORTC_MINUTE 8
#define FF_NORTC_SECOND 0
static DWORD fattime = (
(DWORD)(FF_NORTC_YEAR - 1980) << 25 |
(DWORD)FF_NORTC_MON << 21 |
(DWORD)FF_NORTC_MDAY << 16 |
(DWORD)(FF_NORTC_HOUR << 11) |
(DWORD)(FF_NORTC_MINUTE << 5) |
(DWORD)(FF_NORTC_SECOND)
);
DWORD get_fattime(void)
{
return fattime;
}
void set_fattime(DWORD n)
{
fattime = n;
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
// 漢字コード変換
@ -61,7 +31,6 @@ void set_fattime(DWORD n)
//---------------------------------------------------------------------------
#define IC_BUF_SIZE 1024
static char convert_buf[IC_BUF_SIZE];
#ifndef BAREMETAL
#ifndef __NetBSD__
// POSIX.1準拠iconv(3)を使用
#define CONVERT(src, dest, inbuf, outbuf, outsize) \
@ -100,18 +69,6 @@ static void convert(char const *src, char const *dest,
*outbuf = '\0';
#endif //ifndef __macintosh__
}
#else
// Newlibの中にiconvが含まれてなかったので無変換
// ベアメタルのFatFS上はSJISでもOKだと思うよ
#define CONVERT(src, dest, inbuf, outbuf, outsize) \
convert(src, dest, (char *)inbuf, outbuf, outsize)
static void convert(char const *src, char const *dest,
char *inbuf, char *outbuf, size_t outsize)
{
strcpy(outbuf, inbuf);
strcpy(convert_buf, inbuf);
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
@ -463,16 +420,12 @@ void CHostDrv::GetVolume(TCHAR* szLabel)
ASSERT(m_bEnable);
// ボリュームラベルの取得
#ifdef RASCSI
strcpy(m_szVolumeCache, "RASDRV ");
if (m_szBase[0]) {
strcat(m_szVolumeCache, m_szBase);
} else {
strcat(m_szVolumeCache, "/");
}
#else
m_szVolumeCache[0] = _T('\0');
#endif
// キャッシュ更新
m_bVolumeCache = TRUE;
@ -1624,141 +1577,6 @@ BOOL CHostPath::isRefresh()
return m_bRefresh;
}
#ifdef BAREMETAL
//---------------------------------------------------------------------------
//
/// scandirエミュレーション
//
//---------------------------------------------------------------------------
struct dirent {
char d_name[_MAX_FNAME];
};
int scandir(const char *dirname,
dirent ***ret_namelist,
int(*select)(const dirent *),
int(*compar)(const dirent **, const dirent **))
{
FRESULT fr;
DIR dir;
FILINFO fno;
char dirpath[256];
int len;
dirent went;
int used;
int allocated;
dirent **namelist = NULL;
int i;
dirent *ent;
// NULLチェック
strcpy(dirpath, dirname);
if (dirpath[0] == '\0') {
return -1;
}
// '/'はOKだがそれ以外で最後が'/'だとディレクトリと認識されない)
if (dirpath[0] != '/' || dirpath[1] != '\0') {
len = strlen(dirpath);
if (dirpath[len - 1] == '/') {
dirpath[len - 1] = '\0';
}
}
// ディレクトリオープン
fr = f_opendir(&dir, dirpath);
if (fr != FR_OK) {
return -1;
}
// リストを初期値で確保(とりあえず32)
used = 0;
allocated = 32;
namelist = (dirent **)malloc(allocated * sizeof(dirent *));
if (!namelist) {
goto error;
}
// 配下のファイルまたはディレクトリを処理
i = 0;
while (TRUE) {
if (i == 0) {
// "."をFILINFOに見せかけて追加
strcpy(fno.fname, ".");
i++;
} else if (i == 1) {
// ".."をFILINFOに見せかけて追加
strcpy(fno.fname, "..");
i++;
} else if (f_readdir(&dir, &fno) != FR_OK) {
break;
}
// このケースがあるか不明
if (fno.fname[0] == 0) {
break;
}
// direntに見せかける
strcpy(went.d_name, fno.fname);
// 対象外のフィルタ処理
if (select != NULL && !select(&went)) {
continue;
}
// ファイル名の長さに調整したdirentの領域を確保
len = offsetof(dirent, d_name) + strlen(fno.fname) + 1;
if ((ent = (dirent *)malloc(len)) == NULL) {
goto error;
}
// ワーク用direntから返却用にコピー
memcpy(ent, &went, len);
// 使用量が越えそうならリストを再確保
if (used >= allocated) {
allocated *= 2;
namelist = (dirent **)realloc(namelist, allocated * sizeof(dirent *));
if (!namelist) {
goto error;
}
}
// リストに追加
namelist[used++] = ent;
}
// ディレクトリクローズ
f_closedir(&dir);
// ソート処理
if (compar) {
qsort(
namelist, used, sizeof(dirent *),
(int(*)(const void *, const void *)) compar);
}
// リストとエントリ数を返却
*ret_namelist = namelist;
return used;
error:
// ディレクトリクローズ
f_closedir(&dir);
// 途中まで確保したバッファをクローズ
if (namelist) {
while (used > 0) {
free(namelist[used - 1]);
used--;
}
free(namelist);
}
return -1;
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
/// ASCIIソート関数
@ -1859,12 +1677,8 @@ void CHostPath::Refresh()
// 一致するものがなければ、実ファイルが存在するか確認
strcpy(szPath, m_szHost);
strcat(szPath, (const char*)pFilename->GetHuman()); /// @warning Unicode時要修正 → 済
#ifndef BAREMETAL
struct stat sb;
if (stat(S2U(szPath), &sb))
#else
if (f_stat(S2U(szPath), NULL) != FR_OK)
#endif // BAREMETAL
break; // 利用可能パターンを発見
}
}
@ -1880,7 +1694,6 @@ void CHostPath::Refresh()
strcpy(szPath, m_szHost);
strcat(szPath, U2S(pe->d_name));
#ifndef BAREMETAL
struct stat sb;
if (stat(S2U(szPath), &sb))
continue;
@ -1907,27 +1720,6 @@ void CHostPath::Refresh()
}
pFilename->SetEntryDate(nHumanDate);
pFilename->SetEntryTime(nHumanTime);
#else
FILINFO fno;
if (f_stat(S2U(szPath), &fno) != FR_OK)
continue;
// 属性
BYTE nHumanAttribute = Human68k::AT_ARCHIVE;
if (fno.fattrib & AM_DIR)
nHumanAttribute = Human68k::AT_DIRECTORY;
if (fno.fattrib & AM_RDO)
nHumanAttribute |= Human68k::AT_READONLY;
pFilename->SetEntryAttribute(nHumanAttribute);
// サイズ
DWORD nHumanSize = (DWORD)fno.fsize;
pFilename->SetEntrySize(nHumanSize);
// 日付時刻
pFilename->SetEntryDate(fno.fdate);
pFilename->SetEntryTime(fno.ftime);
#endif // BAREMETAL
// クラスタ番号設定
pFilename->SetEntryCluster(0);
@ -1975,7 +1767,6 @@ void CHostPath::Refresh()
//---------------------------------------------------------------------------
void CHostPath::Backup()
{
#ifndef BAREMETAL
ASSERT(m_szHost);
ASSERT(strlen(m_szHost) < FILEPATH_MAX);
@ -1992,28 +1783,6 @@ void CHostPath::Backup()
if (stat(S2U(szPath), &sb) == 0)
m_tBackup = sb.st_mtime;
}
#else
FILINFO fno;
ASSERT(m_szHost);
ASSERT(strlen(m_szHost) < FILEPATH_MAX);
TCHAR szPath[FILEPATH_MAX];
strcpy(szPath, m_szHost);
size_t len = strlen(szPath);
m_tBackupD = 0;
m_tBackupT = 0;
if (len > 1) { // ルートディレクトリの場合は何もしない
len--;
ASSERT(szPath[len] == _T('/'));
szPath[len] = _T('\0');
if (f_stat(S2U(szPath), &fno) == FR_OK) {
m_tBackupD = fno.fdate;
m_tBackupT = fno.ftime;
}
}
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2023,7 +1792,6 @@ void CHostPath::Backup()
//---------------------------------------------------------------------------
void CHostPath::Restore() const
{
#ifndef BAREMETAL
ASSERT(m_szHost);
ASSERT(strlen(m_szHost) < FILEPATH_MAX);
@ -2042,27 +1810,6 @@ void CHostPath::Restore() const
ut.modtime = m_tBackup;
utime(szPath, &ut);
}
#else
FILINFO fno;
ASSERT(m_szHost);
ASSERT(strlen(m_szHost) < FILEPATH_MAX);
TCHAR szPath[FILEPATH_MAX];
strcpy(szPath, m_szHost);
size_t len = strlen(szPath);
if (m_tBackupD) {
ASSERT(len);
len--;
ASSERT(szPath[len] == _T('/'));
szPath[len] = _T('\0');
fno.fdate = m_tBackupD;
fno.ftime = m_tBackupT;
f_utime(szPath, &fno);
}
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2683,13 +2430,8 @@ void CHostFilesManager::Free(CHostFiles* pFiles)
//---------------------------------------------------------------------------
void CHostFcb::Init()
{
m_bUpdate = FALSE;
#ifndef BAREMETAL
m_pFile = NULL;
#else
memset(&m_File, 0x00, sizeof(FIL));
#endif
}
//---------------------------------------------------------------------------
@ -2699,8 +2441,6 @@ void CHostFcb::Init()
//---------------------------------------------------------------------------
BOOL CHostFcb::SetMode(DWORD nHumanMode)
{
#ifndef BAREMETAL
switch (nHumanMode & Human68k::OP_MASK) {
case Human68k::OP_READ:
m_pszMode = "rb";
@ -2714,21 +2454,6 @@ BOOL CHostFcb::SetMode(DWORD nHumanMode)
default:
return FALSE;
}
#else
switch (nHumanMode & Human68k::OP_MASK) {
case Human68k::OP_READ:
m_Mode = FA_READ;
break;
case Human68k::OP_WRITE:
m_Mode = FA_WRITE;
break;
case Human68k::OP_FULL:
m_Mode = FA_WRITE | FA_READ;
break;
default:
return FALSE;
}
#endif // BAREMETAL
m_bFlag = (nHumanMode & Human68k::OP_SPECIAL) != 0;
@ -2770,7 +2495,6 @@ void CHostFcb::SetHumanPath(const BYTE* szHumanPath)
//---------------------------------------------------------------------------
BOOL CHostFcb::Create(Human68k::fcb_t* pFcb, DWORD nHumanAttribute, BOOL bForce)
{
#ifndef BAREMETAL
ASSERT((nHumanAttribute & (Human68k::AT_DIRECTORY | Human68k::AT_VOLUME)) == 0);
ASSERT(strlen(m_szFilename) > 0);
ASSERT(m_pFile == NULL);
@ -2786,28 +2510,6 @@ BOOL CHostFcb::Create(Human68k::fcb_t* pFcb, DWORD nHumanAttribute, BOOL bForce)
m_pFile = fopen(S2U(m_szFilename), "w+b"); /// @warning 理想動作は属性ごと上書き
return m_pFile != NULL;
#else
FRESULT fr;
ASSERT((nHumanAttribute & (Human68k::AT_DIRECTORY | Human68k::AT_VOLUME)) == 0);
ASSERT(strlen(m_szFilename) > 0);
// 重複チェック
if (bForce == FALSE) {
if (f_stat(S2U(m_szFilename), NULL) == FR_OK)
return FALSE;
}
// RPIのベアメタルではRTCが無いのでHuman側の時刻を反映させる
DWORD nHumanTime = ((DWORD)pFcb->date) << 16 | ((DWORD)pFcb->time);
set_fattime(nHumanTime);
// ファイル作成
fr = f_open(&m_File, S2U(m_szFilename), FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
/// @warning 理想動作は属性ごと上書き
return fr == FR_OK;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2819,7 +2521,6 @@ BOOL CHostFcb::Create(Human68k::fcb_t* pFcb, DWORD nHumanAttribute, BOOL bForce)
//---------------------------------------------------------------------------
BOOL CHostFcb::Open()
{
#ifndef BAREMETAL
struct stat st;
ASSERT(strlen(m_szFilename) > 0);
@ -2836,26 +2537,6 @@ BOOL CHostFcb::Open()
m_pFile = fopen(S2U(m_szFilename), m_pszMode);
return m_pFile != NULL || m_bFlag;
#else
FRESULT fr;
FILINFO fno;
ASSERT(strlen(m_szFilename) > 0);
// ディレクトリなら失敗
if (f_stat(S2U(m_szFilename), &fno) == FR_OK) {
if (fno.fattrib & AM_DIR) {
return FALSE || m_bFlag;
}
}
// ファイルオープン
fr = FR_DISK_ERR;
if (m_File.obj.fs == NULL)
fr = f_open(&m_File, S2U(m_szFilename), m_Mode);
return fr == FR_OK || m_bFlag;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2867,19 +2548,12 @@ BOOL CHostFcb::Open()
//---------------------------------------------------------------------------
BOOL CHostFcb::Rewind(DWORD nOffset)
{
#ifndef BAREMETAL
ASSERT(m_pFile);
if (fseek(m_pFile, nOffset, SEEK_SET))
return FALSE;
return ftell(m_pFile) != -1L;
#else
if (f_lseek(&m_File, nOffset))
return FALSE;
return f_tell(&m_File) != (DWORD)-1L;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2892,7 +2566,6 @@ BOOL CHostFcb::Rewind(DWORD nOffset)
//---------------------------------------------------------------------------
DWORD CHostFcb::Read(BYTE* pBuffer, DWORD nSize)
{
#ifndef BAREMETAL
ASSERT(pBuffer);
ASSERT(m_pFile);
@ -2901,18 +2574,6 @@ DWORD CHostFcb::Read(BYTE* pBuffer, DWORD nSize)
nResult = (size_t)-1;
return (DWORD)nResult;
#else
FRESULT fr;
UINT nResult;
ASSERT(pBuffer);
fr = f_read(&m_File, pBuffer, nSize, &nResult);
if (fr != FR_OK)
nResult = (UINT)-1;
return (DWORD)nResult;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2925,7 +2586,6 @@ DWORD CHostFcb::Read(BYTE* pBuffer, DWORD nSize)
//---------------------------------------------------------------------------
DWORD CHostFcb::Write(const BYTE* pBuffer, DWORD nSize)
{
#ifndef BAREMETAL
ASSERT(pBuffer);
ASSERT(m_pFile);
@ -2934,18 +2594,6 @@ DWORD CHostFcb::Write(const BYTE* pBuffer, DWORD nSize)
nResult = (size_t)-1;
return (DWORD)nResult;
#else
FRESULT fr;
UINT nResult;
ASSERT(pBuffer);
fr = f_write(&m_File, pBuffer, nSize, &nResult);
if (fr != FR_OK)
nResult = (UINT)-1;
return (DWORD)nResult;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2957,13 +2605,9 @@ DWORD CHostFcb::Write(const BYTE* pBuffer, DWORD nSize)
//---------------------------------------------------------------------------
BOOL CHostFcb::Truncate()
{
#ifndef BAREMETAL
ASSERT(m_pFile);
return ftruncate(fileno(m_pFile), ftell(m_pFile)) == 0;
#else
return f_truncate(&m_File) == FR_OK;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -2975,7 +2619,6 @@ BOOL CHostFcb::Truncate()
//---------------------------------------------------------------------------
DWORD CHostFcb::Seek(DWORD nOffset, DWORD nHumanSeek)
{
#ifndef BAREMETAL
ASSERT(nHumanSeek == Human68k::SK_BEGIN ||
nHumanSeek == Human68k::SK_CURRENT || nHumanSeek == Human68k::SK_END);
ASSERT(m_pFile);
@ -2997,29 +2640,6 @@ DWORD CHostFcb::Seek(DWORD nOffset, DWORD nHumanSeek)
return (DWORD)-1;
return (DWORD)ftell(m_pFile);
#else
FRESULT fr;
ASSERT(nHumanSeek == Human68k::SK_BEGIN ||
nHumanSeek == Human68k::SK_CURRENT || nHumanSeek == Human68k::SK_END);
switch (nHumanSeek) {
case Human68k::SK_BEGIN:
fr = f_lseek(&m_File, nOffset);
break;
case Human68k::SK_CURRENT:
fr = f_lseek(&m_File, f_tell(&m_File) + nOffset);
break;
// case SK_END:
default:
fr = f_lseek(&m_File, f_size(&m_File) + nOffset);
break;
}
if (fr != FR_OK)
return (DWORD)-1;
return (DWORD)f_tell(&m_File);
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -3031,7 +2651,6 @@ DWORD CHostFcb::Seek(DWORD nOffset, DWORD nHumanSeek)
//---------------------------------------------------------------------------
BOOL CHostFcb::TimeStamp(DWORD nHumanTime)
{
#ifndef BAREMETAL
ASSERT(m_pFile || m_bFlag);
struct tm t = { 0 };
@ -3053,19 +2672,6 @@ BOOL CHostFcb::TimeStamp(DWORD nHumanTime)
fflush(m_pFile);
return utime(S2U(m_szFilename), &ut) == 0 || m_bFlag;
#else
FILINFO fno;
ASSERT(m_bFlag);
// クローズ時に更新時刻が上書きされるのを防止するため
// タイムスタンプの更新前にフラッシュして同期させる
f_sync(&m_File);
fno.fdate = (WORD)(nHumanTime >> 16);
fno.ftime = (WORD)nHumanTime;
return f_utime(S2U(m_szFilename), &fno) == FR_OK || m_bFlag;
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -3077,19 +2683,14 @@ BOOL CHostFcb::TimeStamp(DWORD nHumanTime)
//---------------------------------------------------------------------------
BOOL CHostFcb::Close()
{
BOOL bResult = TRUE;
// ファイルクローズ
// Close→Free(内部で再度Close)という流れもあるので必ず初期化すること。
#ifndef BAREMETAL
if (m_pFile) {
fclose(m_pFile);
m_pFile = NULL;
}
#else
f_close(&m_File);
#endif // BAREMETAL
return bResult;
}
@ -3409,11 +3010,7 @@ int CFileSys::MakeDir(DWORD nUnit, const Human68k::namests_t* pNamests)
f.AddFilename();
// ディレクトリ作成
#ifndef BAREMETAL
if (mkdir(S2U(f.GetPath()), 0777))
#else
if (f_mkdir(S2U(f.GetPath())) != FR_OK)
#endif // BAREMETAL
return FS_INVALIDPATH;
// キャッシュ更新
@ -3463,11 +3060,7 @@ int CFileSys::RemoveDir(DWORD nUnit, const Human68k::namests_t* pNamests)
m_cEntry.DeleteCache(nUnit, szHuman);
// ディレクトリ削除
#ifndef BAREMETAL
if (rmdir(S2U(f.GetPath())))
#else
if (f_rmdir(S2U(f.GetPath())) != FR_OK)
#endif // BAREMETAL
return FS_CANTDELETE;
// キャッシュ更新
@ -3523,11 +3116,7 @@ int CFileSys::Rename(DWORD nUnit, const Human68k::namests_t* pNamests, const Hum
char szTo[FILENAME_MAX];
SJIS2UTF8(f.GetPath(), szFrom, FILENAME_MAX);
SJIS2UTF8(fNew.GetPath(), szTo, FILENAME_MAX);
#ifndef BAREMETAL
if (rename(szFrom, szTo)) {
#else
if (f_rename(szFrom, szTo) != FR_OK) {
#endif // BAREMETAL
return FS_FILENOTFND;
}
@ -3569,11 +3158,7 @@ int CFileSys::Delete(DWORD nUnit, const Human68k::namests_t* pNamests)
return FS_FILENOTFND;
// ファイル削除
#ifndef BAREMETAL
if (unlink(S2U(f.GetPath())))
#else
if (f_unlink(S2U(f.GetPath())) != FR_OK)
#endif // BAREMETAL
return FS_CANTDELETE;
// キャッシュ更新
@ -3624,7 +3209,6 @@ int CFileSys::Attribute(DWORD nUnit, const Human68k::namests_t* pNamests, DWORD
DWORD nAttribute = (nHumanAttribute & Human68k::AT_READONLY) |
(f.GetAttribute() & ~Human68k::AT_READONLY);
if (f.GetAttribute() != nAttribute) {
#ifndef BAREMETAL
struct stat sb;
if (stat(S2U(f.GetPath()), &sb))
return FS_FILENOTFND;
@ -3637,17 +3221,6 @@ int CFileSys::Attribute(DWORD nUnit, const Human68k::namests_t* pNamests, DWORD
// 属性設定
if (chmod(S2U(f.GetPath()), m))
return FS_FILENOTFND;
#else
if (f_stat(S2U(f.GetPath()), NULL) != FR_OK)
return FS_FILENOTFND;
BYTE m = 0;
if (nAttribute & Human68k::AT_READONLY)
m = AM_RDO;
// 属性設定
if (f_chmod(S2U(f.GetPath()), m, AM_RDO))
return FS_FILENOTFND;
#endif // BAREMETAL
}
// キャッシュ更新

View File

@ -14,11 +14,6 @@
#ifndef cfilesystem_h
#define cfilesystem_h
#ifdef BAREMETAL
#include "ffconf.h"
#include "ff.h"
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
// ステータスコード定義
@ -572,12 +567,7 @@ private:
///< 文字列比較 (ワイルドカード対応)
CRing m_cRing; ///< CHostFilename連結用
#ifndef BAREMETAL
time_t m_tBackup; ///< 時刻復元用
#else
WORD m_tBackupD; ///< 時刻復元用
WORD m_tBackupT; ///< 時刻復元用
#endif // BAREMETAL
BOOL m_bRefresh; ///< 更新フラグ
DWORD m_nId; ///< 識別ID (値が変化した場合は更新を意味する)
BYTE m_szHuman[HUMAN68K_PATH_MAX]; ///< 該当エントリのHuman68k内部名
@ -715,13 +705,8 @@ public:
private:
DWORD m_nKey; ///< Human68kのFCBバッファアドレス (0なら未使用)
BOOL m_bUpdate; ///< 更新フラグ
#ifndef BAREMETAL
FILE* m_pFile; ///< ホスト側のファイルオブジェクト
const char* m_pszMode; ///< ホスト側のファイルオープンモード
#else
FIL m_File; ///< ホスト側のファイルオブジェクト
BYTE m_Mode; ///< ホスト側のファイルオープンモード
#endif // BAREMETAL
bool m_bFlag; ///< ホスト側のファイルオープンフラグ
BYTE m_szHumanPath[HUMAN68K_PATH_MAX];
///< Human68kのパス名

View File

@ -21,21 +21,10 @@
#include "xm6.h"
#include "filepath.h"
#include "fileio.h"
#ifdef RASCSI
#include "gpiobus.h"
#ifndef BAREMETAL
#include "ctapdriver.h"
#endif // BAREMETAL
#include "cfilesystem.h"
#include "disk.h"
#else
#include "vm.h"
#include "disk.h"
#include "windrv.h"
#include "ctapdriver.h"
#include "mfc_com.h"
#include "mfc_host.h"
#endif // RASCSI
//===========================================================================
//
@ -157,13 +146,9 @@ BOOL FASTCALL DiskTrack::Load(const Filepath& path)
ASSERT((dt.sectors > 0) && (dt.sectors <= 0x100));
if (dt.buffer == NULL) {
#if defined(RASCSI) && !defined(BAREMETAL)
if (posix_memalign((void **)&dt.buffer, 512, ((length + 511) / 512) * 512)) {
LOGWARN("%s posix_memalign failed", __PRETTY_FUNCTION__);
}
#else
dt.buffer = (BYTE *)malloc(length * sizeof(BYTE));
#endif // RASCSI && !BAREMETAL
dt.length = length;
}
@ -174,13 +159,9 @@ BOOL FASTCALL DiskTrack::Load(const Filepath& path)
// Reallocate if the buffer length is different
if (dt.length != (DWORD)length) {
free(dt.buffer);
#if defined(RASCSI) && !defined(BAREMETAL)
if (posix_memalign((void **)&dt.buffer, 512, ((length + 511) / 512) * 512)) {
LOGWARN("%s posix_memalign failed", __PRETTY_FUNCTION__);
}
#else
dt.buffer = (BYTE *)malloc(length * sizeof(BYTE));
#endif // RASCSI && !BAREMETAL
dt.length = length;
}
@ -205,11 +186,7 @@ BOOL FASTCALL DiskTrack::Load(const Filepath& path)
memset(dt.changemap, 0x00, dt.sectors * sizeof(BOOL));
// Read from File
#if defined(RASCSI) && !defined(BAREMETAL)
if (!fio.OpenDIO(path, Fileio::ReadOnly)) {
#else
if (!fio.Open(path, Fileio::ReadOnly)) {
#endif // RASCSI && !BAREMETAL
return FALSE;
}
if (dt.raw) {
@ -783,138 +760,6 @@ void FASTCALL Disk::Reset()
disk.reset = TRUE;
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Save
//
//---------------------------------------------------------------------------
BOOL FASTCALL Disk::Save(Fileio *fio, int ver)
{
DWORD padding;
ASSERT(fio);
// Save size
DWORD sz = 52;
if (!fio->Write(&sz, sizeof(sz))) {
return FALSE;
}
// Save entity
PROP_EXPORT(fio, disk.id);
PROP_EXPORT(fio, disk.ready);
PROP_EXPORT(fio, disk.writep);
PROP_EXPORT(fio, disk.readonly);
PROP_EXPORT(fio, disk.removable);
PROP_EXPORT(fio, disk.lock);
PROP_EXPORT(fio, disk.attn);
PROP_EXPORT(fio, disk.reset);
PROP_EXPORT(fio, disk.size);
PROP_EXPORT(fio, disk.blocks);
PROP_EXPORT(fio, disk.lun);
PROP_EXPORT(fio, disk.code);
PROP_EXPORT(fio, padding);
// Save the path
if (!diskpath.Save(fio, ver)) {
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
//
// Load
//
//---------------------------------------------------------------------------
BOOL FASTCALL Disk::Load(Fileio *fio, int ver)
{
DWORD sz;
disk_t buf;
DWORD padding;
Filepath path;
ASSERT(fio);
// Prior to version 2.03, the disk was not saved
if (ver <= 0x0202) {
return TRUE;
}
// Delete the current disk cache
if (disk.dcache) {
disk.dcache->Save();
delete disk.dcache;
disk.dcache = NULL;
}
// Load size
if (!fio->Read(&sz, sizeof(sz))) {
return FALSE;
}
if (sz != 52) {
return FALSE;
}
// Load into buffer
PROP_IMPORT(fio, buf.id);
PROP_IMPORT(fio, buf.ready);
PROP_IMPORT(fio, buf.writep);
PROP_IMPORT(fio, buf.readonly);
PROP_IMPORT(fio, buf.removable);
PROP_IMPORT(fio, buf.lock);
PROP_IMPORT(fio, buf.attn);
PROP_IMPORT(fio, buf.reset);
PROP_IMPORT(fio, buf.size);
PROP_IMPORT(fio, buf.blocks);
PROP_IMPORT(fio, buf.lun);
PROP_IMPORT(fio, buf.code);
PROP_IMPORT(fio, padding);
// Load path
if (!path.Load(fio, ver)) {
return FALSE;
}
// Move only if IDs match
if (disk.id == buf.id) {
// Do nothing if null
if (IsNULL()) {
return TRUE;
}
// Same type of device as when saving
disk.ready = FALSE;
if (Open(path)) {
// Disk cache is created in Open
// move only properties
if (!disk.readonly) {
disk.writep = buf.writep;
}
disk.lock = buf.lock;
disk.attn = buf.attn;
disk.reset = buf.reset;
disk.lun = buf.lun;
disk.code = buf.code;
// Loaded successfully
return TRUE;
}
}
// Disk cache rebuild
if (!IsReady()) {
disk.dcache = NULL;
} else {
disk.dcache = new DiskCache(diskpath, disk.size, disk.blocks);
}
return TRUE;
}
#endif // RASCSI
//---------------------------------------------------------------------------
//
// NULL Check

View File

@ -60,14 +60,7 @@
#define DISK_AUDIOCOMPLETE 0x00??0013 // AUDIO PLAY SUCCESSFULLY COMPLETED
#endif
#ifdef RASCSI
#define BENDER_SIGNATURE "RaSCSI"
// The following line was to mimic Apple's CDROM ID
// #define BENDER_SIGNATURE "SONY "
#else
#define BENDER_SIGNATURE "XM6"
#endif
//===========================================================================
//
@ -192,10 +185,6 @@ public:
Disk(); // Constructor
virtual ~Disk(); // Destructor
virtual void FASTCALL Reset(); // Device Reset
#ifndef RASCSI
virtual BOOL FASTCALL Save(Fileio *fio, int ver); // Save
virtual BOOL FASTCALL Load(Fileio *fio, int ver); // Load
#endif // RASCSI
// ID
DWORD FASTCALL GetID() const; // Get media ID

View File

@ -53,7 +53,7 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk()
// DaynaPort
disk.id = MAKEID('S', 'C', 'D', 'P');
#if defined(__linux__) && !defined(BAREMETAL)
#ifdef __linux__
// TAP Driver Generation
m_tap = new CTapDriver();
m_bTapEnable = m_tap->Init();
@ -86,7 +86,7 @@ SCSIDaynaPort::SCSIDaynaPort() : Disk()
m_mac_addr[4]=0x98;
m_mac_addr[5]=0xE3;
#endif // RASCSI && !BAREMETAL
#endif // linux
LOGTRACE("SCSIDaynaPort Constructor End");
}

View File

@ -173,9 +173,6 @@ private:
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#if defined(RASCSI) && !defined(BAREMETAL)
CTapDriver *m_tap;
// TAP driver
BOOL m_bTapEnable;
@ -184,7 +181,4 @@ private:
// MAC Address
static const BYTE m_bcast_addr[6];
static const BYTE m_apple_talk_addr[6];
#endif // RASCSI && !BAREMETAL
};

View File

@ -42,7 +42,7 @@ SCSIBR::SCSIBR() : Disk()
// Host Bridge
disk.id = MAKEID('S', 'C', 'B', 'R');
#if defined(RASCSI) && defined(__linux__) && !defined(BAREMETAL)
#ifdef __linux__
// TAP Driver Generation
tap = new CTapDriver();
m_bTapEnable = tap->Init();
@ -56,7 +56,7 @@ SCSIBR::SCSIBR() : Disk()
// Packet reception flag OFF
packet_enable = FALSE;
#endif // RASCSI && !BAREMETAL
#endif
// Create host file system
fs = new CFileSys();
@ -70,13 +70,11 @@ SCSIBR::SCSIBR() : Disk()
//---------------------------------------------------------------------------
SCSIBR::~SCSIBR()
{
#if defined(RASCSI) && !defined(BAREMETAL)
// TAP driver release
if (tap) {
tap->Cleanup();
delete tap;
}
#endif // RASCSI && !BAREMETAL
// Release host file system
if (fs) {
@ -139,12 +137,10 @@ int FASTCALL SCSIBR::Inquiry(
// Optional function valid flag
buf[36] = '0';
#if defined(RASCSI) && !defined(BAREMETAL)
// TAP Enable
if (m_bTapEnable) {
buf[37] = '1';
}
#endif // RASCSI && !BAREMETAL
// CFileSys Enable
buf[38] = '1';
@ -181,25 +177,20 @@ BOOL FASTCALL SCSIBR::TestUnitReady(const DWORD* /*cdb*/)
//---------------------------------------------------------------------------
int FASTCALL SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
{
#if defined(RASCSI) && !defined(BAREMETAL)
int func;
int total_len;
int i;
#endif // RASCSI && !BAREMETAL
// Type
int type = cdb[2];
#if defined(RASCSI) && !defined(BAREMETAL)
// Function number
func = cdb[3];
#endif // RASCSI && !BAREMETAL
// Phase
int phase = cdb[9];
switch (type) {
#if defined(RASCSI) && !defined(BAREMETAL)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
@ -248,7 +239,6 @@ int FASTCALL SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
return total_len;
}
break;
#endif // RASCSI && !BAREMETAL
case 2: // Host Drive
switch (phase) {
@ -296,7 +286,6 @@ BOOL FASTCALL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
len |= cdb[8];
switch (type) {
#if defined(RASCSI) && !defined(BAREMETAL)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
@ -313,7 +302,6 @@ BOOL FASTCALL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
return TRUE;
}
break;
#endif // RASCSI && !BAREMETAL
case 2: // Host drive
switch (phase) {
@ -333,7 +321,6 @@ BOOL FASTCALL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
return FALSE;
}
#if defined(RASCSI) && !defined(BAREMETAL)
//---------------------------------------------------------------------------
//
// Get MAC Address
@ -433,7 +420,6 @@ void FASTCALL SCSIBR::SendPacket(BYTE *buf, int len)
tap->Tx(buf, len);
}
#endif // RASCSI && !BAREMETAL
//---------------------------------------------------------------------------
//

View File

@ -26,9 +26,7 @@
// SCSI Host Bridge
//
//===========================================================================
#if defined(RASCSI) && !defined(BAREMETAL)
class CTapDriver;
#endif // RASCSI && !BAREMETAL
class CFileSys;
class SCSIBR : public Disk
{
@ -44,7 +42,6 @@ public:
BOOL FASTCALL SendMessage10(const DWORD *cdb, BYTE *buf); // SEND MESSAGE10 command
private:
#if defined(RASCSI) && !defined(BAREMETAL)
int FASTCALL GetMacAddr(BYTE *buf); // Get MAC address
void FASTCALL SetMacAddr(BYTE *buf); // Set MAC address
void FASTCALL ReceivePacket(); // Receive a packet
@ -57,7 +54,6 @@ private:
int packet_len; // Receive packet size
BYTE packet_buf[0x1000]; // Receive packet buffer
BOOL packet_enable; // Received packet valid
#endif // RASCSI && !BAREMETAL
int FASTCALL ReadFsResult(BYTE *buf); // Read filesystem (result code)
int FASTCALL ReadFsOut(BYTE *buf); // Read filesystem (return data)

View File

@ -286,103 +286,6 @@ SCSICD::~SCSICD()
ClearTrack();
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Load
//
//---------------------------------------------------------------------------
BOOL FASTCALL SCSICD::Load(Fileio *fio, int ver)
{
DWORD sz;
disk_t buf;
DWORD padding;
Filepath path;
ASSERT(fio);
ASSERT(ver >= 0x0200);
// Prior to version 2.03, the disk was not saved
if (ver <= 0x0202) {
return TRUE;
}
// load size, match
if (!fio->Read(&sz, sizeof(sz))) {
return FALSE;
}
if (sz != 52) {
return FALSE;
}
// load into buffer
PROP_IMPORT(fio, buf.id);
PROP_IMPORT(fio, buf.ready);
PROP_IMPORT(fio, buf.writep);
PROP_IMPORT(fio, buf.readonly);
PROP_IMPORT(fio, buf.removable);
PROP_IMPORT(fio, buf.lock);
PROP_IMPORT(fio, buf.attn);
PROP_IMPORT(fio, buf.reset);
PROP_IMPORT(fio, buf.size);
PROP_IMPORT(fio, buf.blocks);
PROP_IMPORT(fio, buf.lun);
PROP_IMPORT(fio, buf.code);
PROP_IMPORT(fio, padding);
// Load path
if (!path.Load(fio, ver)) {
return FALSE;
}
// Always eject
Eject(TRUE);
// move only if IDs match
if (disk.id != buf.id) {
// It was not a CD-ROM when saving. Maintain eject status
return TRUE;
}
// Try to reopen
if (!Open(path, FALSE)) {
// Cannot reopen. Maintain eject status
return TRUE;
}
// Disk cache is created in Open. Move property only
if (!disk.readonly) {
disk.writep = buf.writep;
}
disk.lock = buf.lock;
disk.attn = buf.attn;
disk.reset = buf.reset;
disk.lun = buf.lun;
disk.code = buf.code;
// Discard the disk cache again
if (disk.dcache) {
delete disk.dcache;
disk.dcache = NULL;
}
disk.dcache = NULL;
// Tentative
disk.blocks = track[0]->GetBlocks();
if (disk.blocks > 0) {
// Recreate the disk cache
track[0]->GetPath(path);
disk.dcache = new DiskCache(path, disk.size, disk.blocks);
disk.dcache->SetRawMode(rawfile);
// Reset data index
dataindex = 0;
}
return TRUE;
}
#endif // RASCSI
//---------------------------------------------------------------------------
//
// Open

View File

@ -115,9 +115,6 @@ public:
SCSICD(); // Constructor
virtual ~SCSICD(); // Destructor
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
#ifndef RASCSI
BOOL FASTCALL Load(Fileio *fio, int ver); // Load
#endif // RASCSI
// commands
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command

View File

@ -98,85 +98,6 @@ BOOL FASTCALL SCSIMO::Open(const Filepath& path, BOOL attn)
return TRUE;
}
#ifndef RASCSI
//---------------------------------------------------------------------------
//
// Load
//
//---------------------------------------------------------------------------
BOOL FASTCALL SCSIMO::Load(Fileio *fio, int ver)
{
DWORD sz;
disk_t buf;
DWORD padding;
Filepath path;
ASSERT(fio);
ASSERT(ver >= 0x0200);
// Prior to version 2.03, the disk was not saved
if (ver <= 0x0202) {
return TRUE;
}
// load size, match
if (!fio->Read(&sz, sizeof(sz))) {
return FALSE;
}
if (sz != 52) {
return FALSE;
}
// load into buffer
PROP_IMPORT(fio, buf.id);
PROP_IMPORT(fio, buf.ready);
PROP_IMPORT(fio, buf.writep);
PROP_IMPORT(fio, buf.readonly);
PROP_IMPORT(fio, buf.removable);
PROP_IMPORT(fio, buf.lock);
PROP_IMPORT(fio, buf.attn);
PROP_IMPORT(fio, buf.reset);
PROP_IMPORT(fio, buf.size);
PROP_IMPORT(fio, buf.blocks);
PROP_IMPORT(fio, buf.lun);
PROP_IMPORT(fio, buf.code);
PROP_IMPORT(fio, padding);
// Load path
if (!path.Load(fio, ver)) {
return FALSE;
}
// Always eject
Eject(TRUE);
// Move only if IDs match
if (disk.id != buf.id) {
// Not MO at the time of save. Maintain eject status
return TRUE;
}
// Re-try opening
if (!Open(path, FALSE)) {
// Cannot reopen. Maintain eject status
return TRUE;
}
// Disk cache is created in Open. Move property only
if (!disk.readonly) {
disk.writep = buf.writep;
}
disk.lock = buf.lock;
disk.attn = buf.attn;
disk.reset = buf.reset;
disk.lun = buf.lun;
disk.code = buf.code;
// loaded successfully
return TRUE;
}
#endif // RASCSI
//---------------------------------------------------------------------------
//
// INQUIRY

View File

@ -30,9 +30,6 @@ public:
// Basic Functions
SCSIMO(); // Constructor
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
#ifndef RASCSI
BOOL FASTCALL Load(Fileio *fio, int ver); // Load
#endif // RASCSI
// commands
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
@ -40,4 +37,4 @@ public:
// Internal processing
int FASTCALL AddVendor(int page, BOOL change, BYTE *buf); // Add vendor special page
};
};

View File

@ -19,7 +19,6 @@
//
//===========================================================================
#ifndef BAREMETAL
//---------------------------------------------------------------------------
//
// コンストラクタ
@ -332,263 +331,3 @@ void FASTCALL Fileio::Close()
handle = -1;
}
}
#else
//---------------------------------------------------------------------------
//
// コンストラクタ
//
//---------------------------------------------------------------------------
Fileio::Fileio()
{
// ワーク初期化
handle.obj.fs = 0;
}
//---------------------------------------------------------------------------
//
// デストラクタ
//
//---------------------------------------------------------------------------
Fileio::~Fileio()
{
ASSERT(!handle.obj.fs);
// Releaseでの安全策
Close();
}
//---------------------------------------------------------------------------
//
// ロード
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Load(const Filepath& path, void *buffer, int size)
{
ASSERT(buffer);
ASSERT(size > 0);
ASSERT(!handle.obj.fs);
// オープン
if (!Open(path, ReadOnly)) {
return FALSE;
}
// 読み込み
if (!Read(buffer, size)) {
Close();
return FALSE;
}
// クローズ
Close();
return TRUE;
}
//---------------------------------------------------------------------------
//
// セーブ
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Save(const Filepath& path, void *buffer, int size)
{
ASSERT(buffer);
ASSERT(size > 0);
ASSERT(!handle.obj.fs);
// オープン
if (!Open(path, WriteOnly)) {
return FALSE;
}
// 書き込み
if (!Write(buffer, size)) {
Close();
return FALSE;
}
// クローズ
Close();
return TRUE;
}
//---------------------------------------------------------------------------
//
// オープン
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Open(LPCTSTR fname, OpenMode mode)
{
FRESULT fr;
Filepath fpath;
ASSERT(fname);
ASSERT(!handle.obj.fs);
// ヌル文字列からの読み込みは必ず失敗させる
if (fname[0] == _T('\0')) {
return FALSE;
}
// モード別
switch (mode) {
// 読み込みのみ
case ReadOnly:
fr = f_open(&handle, fname, FA_READ);
break;
// 書き込みのみ
case WriteOnly:
fr = f_open(&handle, fname, FA_CREATE_ALWAYS | FA_WRITE);
break;
// 読み書き両方
case ReadWrite:
fr = f_open(&handle, fname, FA_READ | FA_WRITE);
break;
// アペンド
case Append:
fr = f_open(&handle, fname, FA_OPEN_APPEND | FA_WRITE);
break;
// それ以外
default:
fr = FR_NO_PATH;
ASSERT(FALSE);
break;
}
// 結果評価
if (fr != FR_OK) {
return FALSE;
}
// オープン成功
return TRUE;
}
//---------------------------------------------------------------------------
//
// オープン
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Open(const Filepath& path, OpenMode mode)
{
ASSERT(!handle.obj.fs);
return Open(path.GetPath(), mode);
}
//---------------------------------------------------------------------------
//
// 読み込み
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Read(void *buffer, int size)
{
FRESULT fr;
UINT count;
ASSERT(buffer);
ASSERT(size > 0);
ASSERT(handle.obj.fs);
// 読み込み
fr = f_read(&handle, buffer, size, &count);
if (fr != FR_OK || count != (unsigned int)size) {
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
//
// 書き込み
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Write(const void *buffer, int size)
{
FRESULT fr;
UINT count;
ASSERT(buffer);
ASSERT(size > 0);
ASSERT(handle.obj.fs);
// 書き込み
fr = f_write(&handle, buffer, size, &count);
if (fr != FR_OK || count != (unsigned int)size) {
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
//
// シーク
//
//---------------------------------------------------------------------------
BOOL FASTCALL Fileio::Seek(off64_t offset, BOOL relative)
{
FRESULT fr;
ASSERT(offset >= 0);
ASSERT(handle.obj.fs);
// 相対シークならオフセットに現在値を追加
if (relative) {
offset += f_tell(&handle);
}
fr = f_lseek(&handle, offset);
if (fr != FR_OK) {
return FALSE;
}
if (f_tell(&handle) != (DWORD)offset) {
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
//
// ファイルサイズ取得
//
//---------------------------------------------------------------------------
off64_t FASTCALL Fileio::GetFileSize()
{
ASSERT(handle.obj.fs);
return f_size(&handle);
}
//---------------------------------------------------------------------------
//
// ファイル位置取得
//
//---------------------------------------------------------------------------
off64_t FASTCALL Fileio::GetFilePos() const
{
ASSERT(handle.obj.fs);
return f_tell(&handle);
}
//---------------------------------------------------------------------------
//
// クローズ
//
//---------------------------------------------------------------------------
void FASTCALL Fileio::Close()
{
if (handle.obj.fs) {
f_close(&handle);
}
}
#endif //BAREMETAL

View File

@ -13,10 +13,6 @@
#include "filepath.h"
#ifdef BAREMETAL
#include "ff.h"
#endif // BAREMETAL
//===========================================================================
//
// マクロ(Load,Save用)
@ -61,12 +57,10 @@ public:
// オープン
BOOL FASTCALL Open(const Filepath& path, OpenMode mode);
// オープン
#ifndef BAREMETAL
BOOL FASTCALL OpenDIO(LPCTSTR fname, OpenMode mode);
// オープン
BOOL FASTCALL OpenDIO(const Filepath& path, OpenMode mode);
// オープン
#endif // BAREMETAL
BOOL FASTCALL Seek(off64_t offset, BOOL relative = FALSE);
// シーク
BOOL FASTCALL Read(void *buffer, int size);
@ -79,22 +73,14 @@ public:
// ファイル位置取得
void FASTCALL Close();
// クローズ
#ifndef BAREMETAL
BOOL FASTCALL IsValid() const { return (BOOL)(handle != -1); }
#else
BOOL FASTCALL IsValid() const { return (BOOL)(handle.obj.fs != 0); }
#endif // BAREMETAL
// 有効チェック
private:
#ifndef BAREMETAL
BOOL FASTCALL Open(LPCTSTR fname, OpenMode mode, BOOL directIO);
// オープン
int handle; // ファイルハンドル
#else
FIL handle; // ファイルハンドル
#endif // BAREMETAL
};
#endif // fileio_h

View File

@ -84,80 +84,6 @@ void FASTCALL Filepath::SetPath(LPCSTR path)
Split();
}
#ifdef BAREMETAL
//---------------------------------------------------------------------------
//
// 互換関数(dirname) 結果は直ぐにコピーせよ
//
//---------------------------------------------------------------------------
static char dirtmp[2];
char* dirname(char *path)
{
char *p;
if( path == NULL || *path == '\0' ) {
dirtmp[0] = '.';
dirtmp[1] = '\0';
return dirtmp;
}
p = path + strlen(path) - 1;
while( *p == '/' ) {
if( p == path )
return path;
*p-- = '\0';
}
while( p >= path && *p != '/' ) {
p--;
}
if (p < path) {
dirtmp[0] = '.';
dirtmp[1] = '\0';
return dirtmp;
}
if (p == path) {
dirtmp[0] = '/';
dirtmp[1] = '\0';
return dirtmp;
}
*p = 0;
return path;
}
//---------------------------------------------------------------------------
//
// 互換関数(basename) 結果は直ぐにコピーせよ
//
//---------------------------------------------------------------------------
static char basetmp[2];
char* basename(char *path)
{
char *p;
if( path == NULL || *path == '\0' ) {
basetmp[0] = '/';
basetmp[1] = '\0';
return basetmp;
}
p = path + strlen(path) - 1;
while( *p == '/' ) {
if( p == path ) {
return path;
}
*p-- = '\0';
}
while( p >= path && *p != '/' ) {
p--;
}
return p + 1;
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
// パス分離

View File

@ -17,7 +17,6 @@
#include "gpiobus.h"
#include "log.h"
#ifndef BAREMETAL
#ifdef __linux__
//---------------------------------------------------------------------------
//
@ -80,42 +79,6 @@ DWORD bcm_host_get_peripheral_address(void)
return address;
}
#endif // __NetBSD__
#endif // BAREMETAL
#ifdef BAREMETAL
// IO base address
extern uint32_t RPi_IO_Base_Addr;
// Core frequency
extern uint32_t RPi_Core_Freq;
#ifdef USE_SEL_EVENT_ENABLE
//---------------------------------------------------------------------------
//
// Interrupt control function
//
//---------------------------------------------------------------------------
extern "C" {
extern uintptr_t setIrqFuncAddress (void(*ARMaddress)(void));
extern void EnableInterrupts (void);
extern void DisableInterrupts (void);
extern void WaitForInterrupts (void);
}
//---------------------------------------------------------------------------
//
// Interrupt handler
//
//---------------------------------------------------------------------------
static GPIOBUS *self;
extern "C"
void IrqHandler()
{
// Clear interrupt
self->ClearSelectEvent();
}
#endif // USE_SEL_EVENT_ENABLE
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
@ -124,9 +87,6 @@ void IrqHandler()
//---------------------------------------------------------------------------
GPIOBUS::GPIOBUS()
{
#if defined(USE_SEL_EVENT_ENABLE) && defined(BAREMETAL)
self = this;
#endif // USE_SEL_EVENT_ENABLE && BAREMETAL
}
//---------------------------------------------------------------------------
@ -153,21 +113,14 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
int i;
int j;
int pullmode;
#ifndef BAREMETAL
int fd;
#ifdef USE_SEL_EVENT_ENABLE
struct epoll_event ev;
#endif // USE_SEL_EVENT_ENABLE
#endif // BAREMETAL
// Save operation mode
actmode = mode;
#ifdef BAREMETAL
// Get the base address
baseaddr = RPi_IO_Base_Addr;
map = (void*)baseaddr;
#else
// Get the base address
baseaddr = (DWORD)bcm_host_get_peripheral_address();
@ -185,7 +138,7 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
close(fd);
return FALSE;
}
#endif
// Determine the type of raspberry pi from the base address
if (baseaddr == 0xfe000000) {
rpitype = 4;
@ -213,24 +166,10 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
irpctl = (DWORD *)map;
irpctl += IRPT_OFFSET / sizeof(DWORD);
#ifndef BAREMETAL
// Quad-A7 control
qa7regs = (DWORD *)map;
qa7regs += QA7_OFFSET / sizeof(DWORD);
#endif // BAREMETAL
#ifdef BAREMETAL
// Map GIC memory
if (rpitype == 4) {
map = (void*)ARM_GICD_BASE;
gicd = (DWORD *)map;
map = (void*)ARM_GICC_BASE;
gicc = (DWORD *)map;
} else {
gicd = NULL;
gicc = NULL;
}
#else
// Map GIC memory
if (rpitype == 4) {
map = mmap(NULL, 8192,
@ -247,7 +186,6 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
gicc = NULL;
}
close(fd);
#endif // BAREMETAL
// Set Drive Strength to 16mA
DrvConfig(7);
@ -292,7 +230,6 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
// Initialize SEL signal interrupt
#ifdef USE_SEL_EVENT_ENABLE
#ifndef BAREMETAL
// GPIO chip open
fd = open("/dev/gpiochip0", 0);
if (fd == -1) {
@ -375,7 +312,6 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode)
// Enable interrupts
irpctl[IRPT_ENB_IRQ_2] = (1 << (GPIO_IRQ % 32));
}
#endif // BAREMETAL
#endif // USE_SEL_EVENT_ENABLE
// Create work table
@ -405,9 +341,7 @@ void FASTCALL GPIOBUS::Cleanup()
// Release SEL signal interrupt
#ifdef USE_SEL_EVENT_ENABLE
#ifndef BAREMETAL
close(selevreq.fd);
#endif // BAREMETAL
#endif // USE_SEL_EVENT_ENABLE
// Set control signals
@ -1227,17 +1161,6 @@ int FASTCALL GPIOBUS::PollSelectEvent()
{
// clear errno
errno = 0;
#ifdef BAREMETAL
// Enable interrupts
EnableInterrupts();
// Wait for interrupts
WaitForInterrupts();
// Disable interrupts
DisableInterrupts();
#else
struct epoll_event epev;
struct gpioevent_data gpev;
@ -1250,7 +1173,6 @@ int FASTCALL GPIOBUS::PollSelectEvent()
LOGWARN("%s read failed", __PRETTY_FUNCTION__);
return -1;
}
#endif // BAREMETAL
return 0;
}
@ -1262,21 +1184,6 @@ int FASTCALL GPIOBUS::PollSelectEvent()
//---------------------------------------------------------------------------
void FASTCALL GPIOBUS::ClearSelectEvent()
{
#ifdef BAREMETAL
DWORD irq;
// Clear event
gpio[GPIO_EDS_0] = 1 << PIN_SEL;
// Response to GIC
if (rpitype == 4) {
// IRQ number
irq = gicc[GICC_IAR] & 0x3FF;
// Interrupt response
gicc[GICC_EOIR] = irq;
}
#endif // BAREMETAL
}
#endif // USE_SEL_EVENT_ENABLE
@ -1522,7 +1429,6 @@ BOOL FASTCALL GPIOBUS::WaitSignal(int pin, BOOL ast)
//---------------------------------------------------------------------------
void FASTCALL GPIOBUS::DisableIRQ()
{
#ifndef BAREMETAL
if (rpitype == 4) {
// RPI4 is disabled by GICC
giccpmr = gicc[GICC_PMR];
@ -1537,7 +1443,6 @@ void FASTCALL GPIOBUS::DisableIRQ()
irptenb = irpctl[IRPT_ENB_IRQ_1];
irpctl[IRPT_DIS_IRQ_1] = irptenb & 0xf;
}
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -1547,7 +1452,6 @@ void FASTCALL GPIOBUS::DisableIRQ()
//---------------------------------------------------------------------------
void FASTCALL GPIOBUS::EnableIRQ()
{
#ifndef BAREMETAL
if (rpitype == 4) {
// RPI4 enables interrupts via the GICC
gicc[GICC_PMR] = giccpmr;
@ -1558,7 +1462,6 @@ void FASTCALL GPIOBUS::EnableIRQ()
// Restart the system timer interrupt with the interrupt controller
irpctl[IRPT_ENB_IRQ_1] = irptenb & 0xf;
}
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -1722,7 +1625,6 @@ volatile DWORD SysTimer::corefreq;
//---------------------------------------------------------------------------
void FASTCALL SysTimer::Init(DWORD *syst, DWORD *armt)
{
#ifndef BAREMETAL
// RPI Mailbox property interface
// Get max clock rate
// Tag: 0x00030004
@ -1736,7 +1638,6 @@ void FASTCALL SysTimer::Init(DWORD *syst, DWORD *armt)
// 0x000000004: CORE
DWORD maxclock[32] = { 32, 0, 0x00030004, 8, 0, 4, 0, 0 };
int fd;
#endif // BAREMETAL
// Save the base address
systaddr = syst;
@ -1746,9 +1647,6 @@ void FASTCALL SysTimer::Init(DWORD *syst, DWORD *armt)
armtaddr[ARMT_CTRL] = 0x00000282;
// Get the core frequency
#ifdef BAREMETAL
corefreq = RPi_Core_Freq / 1000000;
#else
corefreq = 0;
fd = open("/dev/vcio", O_RDONLY);
if (fd >= 0) {
@ -1756,7 +1654,6 @@ void FASTCALL SysTimer::Init(DWORD *syst, DWORD *armt)
corefreq = maxclock[6] / 1000000;
}
close(fd);
#endif // BAREMETAL
}
//---------------------------------------------------------------------------

View File

@ -629,7 +629,6 @@ private:
volatile DWORD *irpctl; // Interrupt control register
#ifndef BAREMETAL
volatile DWORD irptenb; // Interrupt enabled state
volatile DWORD *qa7regs; // QA7 register
@ -639,7 +638,6 @@ private:
volatile DWORD tintctl; // Interupt control
volatile DWORD giccpmr; // GICC priority setting
#endif // BAREMETAL
volatile DWORD *gicd; // GIC Interrupt distributor register
@ -649,11 +647,11 @@ private:
DWORD signals; // All bus signals
#if defined(USE_SEL_EVENT_ENABLE) && !defined(BAREMETAL)
#ifdef USE_SEL_EVENT_ENABLE
struct gpioevent_request selevreq = {}; // SEL signal event request
int epfd; // epoll file descriptor
#endif // USE_SEL_EVENT_ENABLE && !BAREMETAL
#endif // USE_SEL_EVENT_ENABLE
#if SIGNAL_CONTROL_MODE == 0
DWORD tblDatMsk[3][256]; // Data mask table

View File

@ -56,7 +56,6 @@
#include <sys/stat.h>
#include <sys/time.h>
#ifndef BAREMETAL
#include <poll.h>
#include <dirent.h>
#include <sys/mman.h>
@ -65,13 +64,6 @@
#include <sys/epoll.h>
#include <netinet/in.h>
#include <linux/gpio.h>
#else
#include <machine/endian.h>
#define htonl(_x) __htonl(_x)
#define htons(_x) __htons(_x)
#define ntohl(_x) __ntohl(_x)
#define ntohs(_x) __ntohs(_x)
#endif // BAREMETAL
#if defined(__linux__)
#include <linux/if.h>

View File

@ -47,11 +47,7 @@ using namespace rasctl_interface;
//---------------------------------------------------------------------------
#define CtrlMax 8 // Maximum number of SCSI controllers
#define UnitNum 2 // Number of units around controller
#ifdef BAREMETAL
#define FPRT(fp, ...) printf( __VA_ARGS__ )
#else
#define FPRT(fp, ...) fprintf(fp, __VA_ARGS__ )
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
@ -63,16 +59,11 @@ static volatile BOOL active; // Processing flag
SASIDEV *ctrl[CtrlMax]; // Controller
Disk *disk[CtrlMax * UnitNum]; // Disk
GPIOBUS *bus; // GPIO Bus
#ifdef BAREMETAL
FATFS fatfs; // FatFS
#else
int monsocket; // Monitor Socket
pthread_t monthread; // Monitor Thread
pthread_mutex_t ctrl_mutex; // Semaphore for the ctrl array
static void *MonThread(void *param);
#endif // BAREMETAL
#ifndef BAREMETAL
//---------------------------------------------------------------------------
//
// Signal Processing
@ -83,7 +74,6 @@ void KillHandler(int sig)
// Stop instruction
running = FALSE;
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
@ -104,14 +94,12 @@ void Banner(int argc, char* argv[])
if ((argc > 1 && strcmp(argv[1], "-h") == 0) ||
(argc > 1 && strcmp(argv[1], "--help") == 0)){
FPRT(stdout,"\n");
FPRT(stdout,"Usage: %s [-IDn FILE] [-s LOG_LEVEL] ...\n\n", argv[0]);
FPRT(stdout,"Usage: %s [-IDn FILE] ...\n\n", argv[0]);
FPRT(stdout," n is SCSI identification number(0-7).\n");
FPRT(stdout," FILE is disk image file.\n");
FPRT(stdout," LOG_LEVEL is {trace|debug|info|warn|err|critical|off}, default is 'trace'\n\n");
FPRT(stdout,"Usage: %s [-HDn FILE] [-s LOG_LEVEL] ...\n\n", argv[0]);
FPRT(stdout," FILE is disk image file.\n\n");
FPRT(stdout,"Usage: %s [-HDn FILE] ...\n\n", argv[0]);
FPRT(stdout," n is X68000 SASI HD number(0-15).\n");
FPRT(stdout," FILE is disk image file, \"daynaport\", or \"bridge\".\n");
FPRT(stdout," LOG_LEVEL is {trace|debug|info|warn|err|critical|off}, default is 'trace'\n\n");
FPRT(stdout," FILE is disk image file, \"daynaport\", or \"bridge\".\n\n");
FPRT(stdout," Image type is detected based on file extension.\n");
FPRT(stdout," hdf : SASI HD image(XM6 SASI HD image)\n");
FPRT(stdout," hds : SCSI HD image(XM6 SCSI HD image)\n");
@ -122,9 +110,7 @@ void Banner(int argc, char* argv[])
FPRT(stdout," mos : SCSI MO image(XM6 SCSI MO image)\n");
FPRT(stdout," iso : SCSI CD image(ISO 9660 image)\n");
#ifndef BAREMETAL
exit(0);
#endif // BAREMETAL
}
}
@ -135,7 +121,6 @@ void Banner(int argc, char* argv[])
//---------------------------------------------------------------------------
BOOL Init()
{
#ifndef BAREMETAL
struct sockaddr_in server;
int yes, result;
@ -146,9 +131,9 @@ BOOL Init()
}
// Create socket for monitor
monsocket = socket(AF_INET, SOCK_STREAM, 0);
monsocket = socket(PF_INET, SOCK_STREAM, 0);
memset(&server, 0, sizeof(server));
server.sin_family = AF_INET;
server.sin_family = PF_INET;
server.sin_port = htons(6868);
server.sin_addr.s_addr = htonl(INADDR_ANY);
@ -179,7 +164,6 @@ BOOL Init()
if (signal(SIGTERM, KillHandler) == SIG_ERR) {
return FALSE;
}
#endif // BAREMETAL
// GPIOBUS creation
bus = new GPIOBUS();
@ -238,14 +222,12 @@ void Cleanup()
// Discard the GPIOBUS object
delete bus;
#ifndef BAREMETAL
// Close the monitor socket
if (monsocket >= 0) {
close(monsocket);
}
pthread_mutex_destroy(&ctrl_mutex);
#endif // BAREMETAL
}
//---------------------------------------------------------------------------
@ -460,12 +442,6 @@ bool MapController(Disk **map)
}
bool ReturnStatus(int fd, bool status = true, const string msg = "") {
#ifdef BAREMETAL
if (msg.length()) {
FPRT(stderr, msg.c_str());
FPRT(stderr, "\n");
}
#else
if (fd == -1) {
if (msg.length()) {
FPRT(stderr, msg.c_str());
@ -475,12 +451,12 @@ bool ReturnStatus(int fd, bool status = true, const string msg = "") {
else {
Result result;
result.set_status(status);
result.set_msg(msg + "\n");
string data;
result.SerializeToString(&data);
SerializeProtobufData(fd, data);
}
#endif
return status;
}
@ -515,7 +491,7 @@ void SetLogLevel(const string& log_level) {
//---------------------------------------------------------------------------
//
// Command Processing. If fd is -1 error messages are displayed on the console.
// Command Processing
//
//---------------------------------------------------------------------------
bool ProcessCmd(int fd, const Command &command)
@ -734,177 +710,6 @@ bool has_suffix(const string& filename, const string& suffix) {
// Argument Parsing
//
//---------------------------------------------------------------------------
#ifdef BAREMETAL
BOOL ParseConfig(int argc, char* argv[])
{
FIL fp;
char line[512];
int id;
int un;
DeviceType type;
char *argID;
char *argPath;
int len;
char *ext;
// Mount the SD card
FRESULT fr = f_mount(&fatfs, "", 1);
if (fr != FR_OK) {
FPRT(stderr, "Error : SD card mount failed.\n");
return FALSE;
}
// If there is no setting file, the processing is interrupted
fr = f_open(&fp, "rascsi.ini", FA_READ);
if (fr != FR_OK) {
return FALSE;
}
// Start Decoding
while (TRUE) {
// Get one Line
memset(line, 0x00, sizeof(line));
if (f_gets(line, sizeof(line) -1, &fp) == NULL) {
break;
}
// Delete the CR/LF
len = strlen(line);
while (len > 0) {
if (line[len - 1] != '\r' && line[len - 1] != '\n') {
break;
}
line[len - 1] = '\0';
len--;
}
// Get the ID and Path
argID = &line[0];
argPath = &line[4];
line[3] = '\0';
// Check if the line is an empty string
if (argID[0] == '\0' || argPath[0] == '\0') {
continue;
}
if (strlen(argID) == 3 && xstrncasecmp(argID, "id", 2) == 0) {
// ID or ID Format
// Check that the ID number is valid (0-7)
if (argID[2] < '0' || argID[2] > '7') {
FPRT(stderr,
"Error : Invalid argument(IDn n=0-7) [%c]\n", argID[2]);
goto parse_error;
}
// The ID unit is good
id = argID[2] - '0';
un = 0;
} else if (xstrncasecmp(argID, "hd", 2) == 0) {
// HD or HD format
if (strlen(argID) == 3) {
// Check that the HD number is valid (0-9)
if (argID[2] < '0' || argID[2] > '9') {
FPRT(stderr,
"Error : Invalid argument(HDn n=0-15) [%c]\n", argID[2]);
goto parse_error;
}
// ID was confirmed
id = (argID[2] - '0') / UnitNum;
un = (argID[2] - '0') % UnitNum;
} else if (strlen(argID) == 4) {
// Check that the HD number is valid (10-15)
if (argID[2] != '1' || argID[3] < '0' || argID[3] > '5') {
FPRT(stderr,
"Error : Invalid argument(HDn n=0-15) [%c]\n", argID[2]);
goto parse_error;
}
// The ID unit is good - create the id and unit number
id = ((argID[3] - '0') + 10) / UnitNum;
un = ((argID[3] - '0') + 10) % UnitNum;
argPath++;
} else {
FPRT(stderr,
"Error : Invalid argument(IDn or HDn) [%s]\n", argID);
goto parse_error;
}
} else {
FPRT(stderr,
"Error : Invalid argument(IDn or HDn) [%s]\n", argID);
goto parse_error;
}
// Skip if there is already an active device
if (disk[id * UnitNum + un] &&
!disk[id * UnitNum + un]->IsNULL()) {
continue;
}
// Check ethernet and host bridge
if (!strcasecmp(argPath, "bridge")) {
type = BR;
} else {
// Check the path length
len = strlen(argPath);
if (len < 5) {
FPRT(stderr,
"Error : Invalid argument(File path is short) [%s]\n",
argPath);
goto parse_error;
}
// Does the file have an extension?
if (argPath[len - 4] != '.') {
FPRT(stderr,
"Error : Invalid argument(No extension) [%s]\n", argPath);
goto parse_error;
}
// Figure out what the type is
ext = &argPath[len - 3];
if (!strcasecmp(ext, "hdf") || !strcasecmp(ext, "hds") || !strcasecmp(ext, "hdn") ||
!strcasecmp(ext, "hdi") || !strcasecmp(ext, "nhd") || !strcasecmp(ext, "hda")) {
type = SASI_HD;
} else if (!strcasecmp(ext, "mos")) {
type = MO;
} else if (!strcasecmp(ext, "iso")) {
type = CD;
}
}
// Execute the command
Command command;
command.set_id(id);
command.set_un(un);
command.set_cmd(0);
command.set_type(type);
command.set_file(argPath);
if (!ProcessCmd(-1, command)) {
goto parse_error;
}
}
// Close the configuration file
f_close(&fp);
// Display the device list
fprintf(stdout, "%s", ListDevice().c_str());
return TRUE;
parse_error:
// Close the configuration file
f_close(&fp);
return FALSE;
}
#else
bool ParseArgument(int argc, char* argv[])
{
int id = -1;
@ -913,7 +718,7 @@ bool ParseArgument(int argc, char* argv[])
string log_level = "trace";
int opt;
while ((opt = getopt(argc, argv, "-IiHhL:s:D:d:")) != -1) {
while ((opt = getopt(argc, argv, "-IiHhL:l:D:d:")) != -1) {
switch (tolower(opt)) {
case 'i':
is_sasi = false;
@ -927,7 +732,7 @@ bool ParseArgument(int argc, char* argv[])
id = -1;
continue;
case 's':
case 'l':
log_level = optarg;
continue;
@ -999,9 +804,7 @@ bool ParseArgument(int argc, char* argv[])
fprintf(stdout, "%s", ListDevice().c_str());
return true;
}
#endif // BAREMETAL
#ifndef BAREMETAL
//---------------------------------------------------------------------------
//
// Pin the thread to a specific CPU
@ -1101,25 +904,14 @@ static void *MonThread(void *param)
return NULL;
}
#endif // BAREMETAL
//---------------------------------------------------------------------------
//
// Main processing
//
//---------------------------------------------------------------------------
#ifdef BAREMETAL
extern "C"
int startrascsi(void)
{
int argc = 0;
char** argv = NULL;
#else
int main(int argc, char* argv[])
{
#endif // BAREMETAL
GOOGLE_PROTOBUF_VERIFY_VERSION;
int i;
int actid;
DWORD now;
@ -1127,9 +919,7 @@ int main(int argc, char* argv[])
BYTE data;
// added setvbuf to override stdout buffering, so logs are written immediately and not when the process exits.
setvbuf(stdout, NULL, _IONBF, 0);
#ifndef BAREMETAL
struct sched_param schparam;
#endif // BAREMETAL
set_level(level::trace);
// Create a thread-safe stdout logger to process the log messages
@ -1148,29 +938,12 @@ int main(int argc, char* argv[])
// Reset
Reset();
#ifdef BAREMETAL
// BUSY assert (to hold the host side)
bus->SetBSY(TRUE);
// Argument parsing
if (!ParseConfig(argc, argv)) {
ret = EINVAL;
goto err_exit;
}
#else
// Argument parsing
if (!ParseArgument(argc, argv)) {
ret = EINVAL;
goto err_exit;
}
#endif
#ifdef BAREMETAL
// Release the busy signal
bus->SetBSY(FALSE);
#endif
#ifndef BAREMETAL
// Set the affinity to a specific processor core
FixCpu(3);
@ -1179,7 +952,6 @@ int main(int argc, char* argv[])
schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0, SCHED_FIFO, &schparam);
#endif // USE_SEL_EVENT_ENABLE
#endif // BAREMETAL
// Start execution
running = TRUE;
@ -1205,9 +977,7 @@ int main(int argc, char* argv[])
#else
bus->Aquire();
if (!bus->GetSEL()) {
#if !defined(BAREMETAL)
usleep(0);
#endif // !BAREMETAL
continue;
}
#endif // USE_SEL_EVENT_ENABLE
@ -1258,11 +1028,11 @@ int main(int argc, char* argv[])
// Start target device
active = TRUE;
#if !defined(USE_SEL_EVENT_ENABLE) && !defined(BAREMETAL)
#ifndef USE_SEL_EVENT_ENABLE
// Scheduling policy setting (highest priority)
schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
sched_setscheduler(0, SCHED_FIFO, &schparam);
#endif // !USE_SEL_EVENT_ENABLE && !BAREMETAL
#endif // USE_SEL_EVENT_ENABLE
// Loop until the bus is free
while (running) {
@ -1277,11 +1047,11 @@ int main(int argc, char* argv[])
pthread_mutex_unlock(&ctrl_mutex);
#if !defined(USE_SEL_EVENT_ENABLE) && !defined(BAREMETAL)
#ifndef USE_SEL_EVENT_ENABLE
// Set the scheduling priority back to normal
schparam.sched_priority = 0;
sched_setscheduler(0, SCHED_OTHER, &schparam);
#endif // !USE_SEL_EVENT_ENABLE && !BAREMETAL
#endif // USE_SEL_EVENT_ENABLE
// End the target travel
active = FALSE;
@ -1292,9 +1062,5 @@ err_exit:
Cleanup();
init_exit:
#if !defined(BAREMETAL)
exit(ret);
#else
return ret;
#endif // BAREMETAL
}