Skip to content

Commit

Permalink
Merge pull request #79 from BlueSCSI/eric/toolbox
Browse files Browse the repository at this point in the history
BlueSCSI Toolbox
  • Loading branch information
erichelgeson authored Oct 12, 2023
2 parents 9aa0b8f + eec90b9 commit 826a371
Show file tree
Hide file tree
Showing 16 changed files with 607 additions and 8 deletions.
25 changes: 25 additions & 0 deletions lib/SCSI2SD/src/firmware/bluescsi_toolbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2023 Eric Helgeson
*
* This file is part of BlueSCSI
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
**/

#ifndef S2S_BLUESCSI_TOOLBOX_H
#define S2S_BLUESCSI_TOOLBOX_H

int scsiBlueSCSIToolboxCommand(void);

#endif
15 changes: 15 additions & 0 deletions lib/SCSI2SD/src/firmware/mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ static const uint8_t AppleVendorPage[] =
'A','P','P','L','E',' ','C','O','M','P','U','T','E','R',',',' ','I','N','C',' ',' ',' '
};

static const uint8_t BlueSCSIVendorPage[] =
{
0x31, // Page code
42, // Page length
'B','l','u','e','S','C','S','I',' ','i','s',' ','t','h','e',' ','B','E','S','T',' ',
'S','T','O','L','E','N',' ','F','R','O','M',' ','B','L','U','E','S','C','S','I',0x00
};

static void pageIn(int pc, int dataIdx, const uint8_t* pageData, int pageLen)
{
memcpy(&scsiDev.data[dataIdx], pageData, pageLen);
Expand Down Expand Up @@ -525,6 +533,13 @@ static void doModeSense(
idx += sizeof(AppleVendorPage);
}

if (pageCode == 0x31 || pageCode == 0x3F)
{
pageFound = 1;
pageIn(pc, idx, BlueSCSIVendorPage, sizeof(BlueSCSIVendorPage));
idx += sizeof(BlueSCSIVendorPage);
}

if (pageCode == 0x38) // Don't send unless requested
{
pageFound = 1;
Expand Down
5 changes: 5 additions & 0 deletions lib/SCSI2SD/src/firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "tape.h"
#include "mo.h"
#include "vendor.h"
#include "bluescsi_toolbox.h"

#include <string.h>

Expand Down Expand Up @@ -587,6 +588,10 @@ static void process_Command()
{
// Already handled.
}
else if (scsiBlueSCSIToolboxCommand())
{
// handled
}
else if (scsiDiskCommand())
{
// Already handled.
Expand Down
7 changes: 6 additions & 1 deletion lib/minIni/minGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <SdFat.h>

#define INI_READONLY 1
#define INI_OPENREWRITE 1
#define INI_FILETYPE FsFile
#define INI_FILEPOS fspos_t

Expand All @@ -11,3 +11,8 @@ bool ini_close(INI_FILETYPE *fp);
bool ini_read(char *buffer, int size, INI_FILETYPE *fp);
void ini_tell(INI_FILETYPE *fp, INI_FILEPOS *pos);
void ini_seek(INI_FILETYPE *fp, INI_FILEPOS *pos);

bool ini_write(char *buffer, INI_FILETYPE *fp);
bool ini_openwrite(const char *filename, INI_FILETYPE *fp);
bool ini_openrewrite(const char *filename, INI_FILETYPE *fp);
void ini_rename(const char *new_name, const char *old_name);
2 changes: 1 addition & 1 deletion lib/minIni/minIni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const T
ini_tell(&rfp, &tail);
/* create new buffer (without writing it to file) */
writekey(LocalBuffer, Key, Value, NULL);
if (_tcslen(LocalBuffer) == (size_t)(tail - head)) {
if (_tcslen(LocalBuffer) == (size_t)(tail.position - head.position)) {
/* length matches, close the file & re-open for read/write, then
* write at the correct position
*/
Expand Down
52 changes: 52 additions & 0 deletions lib/minIni/minIni_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,46 @@ bool ini_openread(const char *filename, INI_FILETYPE *fp)
return fp->open(SD.vol(), filename, O_RDONLY);
}

// Open .ini file either from cache or from SD card
bool ini_openwrite(const char *filename, INI_FILETYPE *fp)
{
#if INI_CACHE_SIZE > 0
if (g_ini_cache.valid &&
(filename == g_ini_cache.filename || strcmp(filename, g_ini_cache.filename) == 0))
{
fp->close();
g_ini_cache.fp = fp;
g_ini_cache.current_pos.position = 0;
return true;
}
#endif

return fp->open(SD.vol(), filename, O_WRONLY);
}

// Open .ini file either from cache or from SD card
bool ini_openrewrite(const char *filename, INI_FILETYPE *fp)
{
#if INI_CACHE_SIZE > 0
if (g_ini_cache.valid &&
(filename == g_ini_cache.filename || strcmp(filename, g_ini_cache.filename) == 0))
{
fp->close();
g_ini_cache.fp = fp;
g_ini_cache.current_pos.position = 0;
return true;
}
#endif

return fp->open(SD.vol(), filename, O_RDWR);
}

void ini_rename(const char * old_name, const char *new_name)
{
SD.rename(old_name, new_name);
invalidate_ini_cache();
}

// Close previously opened file
bool ini_close(INI_FILETYPE *fp)
{
Expand Down Expand Up @@ -116,6 +156,18 @@ bool ini_read(char *buffer, int size, INI_FILETYPE *fp)
}
}

// Write to the card and invalidate the cache.
bool ini_write(char *buffer, INI_FILETYPE *fp)
{
if(fp->write(buffer) > 0)
{
invalidate_ini_cache();
return true;
}
else
return false;
}

// Get the position inside the file
void ini_tell(INI_FILETYPE *fp, INI_FILEPOS *pos)
{
Expand Down
Loading

0 comments on commit 826a371

Please sign in to comment.