Merge pull request #95 from akuker/develop

Merge 21.05.1 changes to master
This commit is contained in:
akuker 2021-05-02 14:05:59 -05:00 committed by GitHub
commit 5548548708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1871 additions and 1951 deletions

8
.gitignore vendored
View File

@ -1 +1,9 @@
venv
*.pyc
core
.idea/
.DS_Store
*.swp
__pycache__
src/web/current
src/oled_monitor/current

View File

@ -24,11 +24,11 @@ VIRTUAL_DRIVER_PATH=/home/pi/images
HFS_FORMAT=/usr/bin/hformat
HFDISK_BIN=/usr/bin/hfdisk
LIDO_DRIVER=~/RASCSI/lido-driver.img
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
function initialChecks() {
currentUser=$(whoami)
if [ "pi" != $currentUser ]; then
if [ "pi" != "$currentUser" ]; then
echo "You must use 'pi' user (current: $currentUser)"
exit 1
fi
@ -40,10 +40,14 @@ function initialChecks() {
fi
}
function installPackages() {
sudo apt-get update && sudo apt install git libspdlog-dev genisoimage python3 python3-venv nginx bridge-utils -y
}
# install all dependency packages for RaSCSI Service
# compile and install RaSCSI Service
function installRaScsi() {
installPackages
sudo apt-get update && sudo apt-get install --yes git libspdlog-dev
cd ~/RASCSI/src/raspberrypi
@ -69,7 +73,7 @@ www-data ALL=NOPASSWD: /sbin/shutdown, /sbin/reboot
function stopOldWebInterface() {
APACHE_STATUS=$(sudo systemctl status apache2 &> /dev/null; echo $?)
if [ $APACHE_STATUS -eq 0 ] ; then
if [ "$APACHE_STATUS" -eq 0 ] ; then
echo "Stopping old Apache2 RaSCSI Web..."
sudo systemctl disable apache2
sudo systemctl stop apache2
@ -79,7 +83,7 @@ function stopOldWebInterface() {
# install everything required to run an HTTP server (Nginx + Python Flask App)
function installRaScsiWebInterface() {
stopOldWebInterface
sudo apt install genisoimage python3 python3-venv nginx -y
installPackages
sudo cp -f ~/RASCSI/src/web/service-infra/nginx-default.conf /etc/nginx/sites-available/default
sudo cp -f ~/RASCSI/src/web/service-infra/502.html /var/www/html/502.html
@ -99,12 +103,17 @@ function installRaScsiWebInterface() {
}
function updateRaScsiGit() {
echo "Updating checked out branch $GIT_BRANCH"
cd ~/RASCSI
git pull
git fetch origin
git stash
git rebase origin/$GIT_BRANCH
git stash apply
}
function updateRaScsi() {
updateRaScsiGit
installPackages
sudo systemctl stop rascsi
cd ~/RASCSI/src/raspberrypi
@ -241,8 +250,8 @@ function showMenu() {
choice=-1
until [ $choice -ge "0" ] && [ $choice -le "7" ]; do
echo "Enter your choice (0-7) or CTRL-C to exit"
read choice
echo -n "Enter your choice (0-7) or CTRL-C to exit: "
read -r choice
done

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# RaSCSI Updates:
# Updates to output rascsi status to an OLED display
@ -29,92 +29,57 @@
# THE SOFTWARE.
import time
import os
import sys
import datetime
#import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import board
import busio
import adafruit_ssd1306
from PIL import Image, ImageDraw, ImageFont
import subprocess
WIDTH = 128
HEIGHT = 32 # Change to 64 if needed
BORDER = 5
# How long to delay between each update
delay_time_ms = 250
# Raspberry Pi pin configuration:
RST = None # on the PiOLED this pin isnt used
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0
# Define the Reset Pin
oled_reset = None
# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0
# init i2c
i2c = board.I2C()
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C, reset=oled_reset)
# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
# Note you can change the I2C address by passing an i2c_address parameter like:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# Alternatively you can specify a software SPI implementation by providing
# digital GPIO pin numbers for all the required display pins. For example
# on a Raspberry Pi with the 128x32 display you might use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22)
print "Running with the following display:"
print disp
print
print "Will update the OLED display every " + str(delay_time_ms) + "ms (approximately)"
# Initialize library.
disp.begin()
print ("Running with the following display:")
print (oled)
print ()
print ("Will update the OLED display every " + str(delay_time_ms) + "ms (approximately)")
# Clear display.
disp.clear()
disp.display()
oled.fill(0)
oled.show()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
image = Image.new("1", (oled.width, oled.height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.rectangle((0,0,WIDTH,HEIGHT), outline=0, fill=0)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height-padding
bottom = HEIGHT-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 0
# Load default font.
font = ImageFont.load_default()
@ -125,10 +90,10 @@ font = ImageFont.load_default()
while True:
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.rectangle((0,0,WIDTH,HEIGHT), outline=0, fill=0)
cmd = "rasctl -l"
rascsi_list = subprocess.check_output(cmd, shell=True)
rascsi_list = subprocess.check_output(cmd, shell=True).decode(sys.stdout.encoding)
y_pos = top
# Draw all of the meaningful data to the 'image'
@ -146,19 +111,20 @@ while True:
for line in rascsi_list.split('\n'):
# Skip empty strings, divider lines and the header line...
if (len(line) == 0) or line.startswith("+---") or line.startswith("| ID | UN"):
continue
else:
if line.startswith("| "):
fields = line.split('|')
output = str.strip(fields[1]) + " " + str.strip(fields[3]) + " " + os.path.basename(str.strip(fields[4]))
else:
output = "No image mounted!"
draw.text((x, y_pos), output, font=font, fill=255)
y_pos = y_pos + 8
continue
else:
if line.startswith("| "):
fields = line.split('|')
output = str.strip(fields[1]) + " " + str.strip(fields[3]) + " " + os.path.basename(str.strip(fields[4]))
else:
output = "No image mounted!"
draw.text((x, y_pos), output, font=font, fill=255)
y_pos += 8
# If there is still room on the screen, we'll display the time. If there's not room it will just be clipped
draw.text((x, y_pos), datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"), font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
oled.image(image)
oled.show()
time.sleep(1/delay_time_ms)

View File

@ -0,0 +1,14 @@
Adafruit-Blinka==6.3.2
adafruit-circuitpython-busdevice==5.0.6
adafruit-circuitpython-framebuf==1.4.6
adafruit-circuitpython-ssd1306==2.11.1
Adafruit-PlatformDetect==3.2.0
Adafruit-PureIO==1.1.8
Pillow==8.1.2
pkg-resources==0.0.0
pyftdi==0.52.9
pyserial==3.5
pyusb==1.1.1
rpi-ws281x==4.2.5
RPi.GPIO==0.7.0
sysv-ipc==1.1.0

76
src/oled_monitor/start.sh Executable file
View File

@ -0,0 +1,76 @@
#!/usr/bin/env bash
set -e
# set -x # Uncomment to Debug
cd $(dirname $0)
# verify packages installed
ERROR=0
if ! command -v dpkg -l i2c-tools &> /dev/null ; then
echo "i2c-tools could not be found"
echo "Run 'sudo apt install i2c-tools' to fix."
ERROR=1
fi
if ! command -v python3 &> /dev/null ; then
echo "python3 could not be found"
echo "Run 'sudo apt install python3' to fix."
ERROR=1
fi
# Dep to build Pillow
if ! dpkg -l python3-dev &> /dev/null; then
echo "python3-dev could not be found"
echo "Run 'sudo apt install python3-dev' to fix."
ERROR=1
fi
if ! dpkg -l libjpeg-dev &> /dev/null; then
echo "libjpeg-dev could not be found"
echo "Run 'sudo apt install libjpeg-dev' to fix."
ERROR=1
fi
if ! dpkg -l libpng-dev &> /dev/null; then
echo "libpng-dev could not be found"
echo "Run 'sudo apt install libpng-dev' to fix."
ERROR=1
fi
# Dep to build Pollow
if ! python3 -m venv --help &> /dev/null ; then
echo "venv could not be found"
echo "Run 'sudo apt install python3-venv' to fix."
ERROR=1
fi
if [ $ERROR = 1 ] ; then
echo
echo "Fix errors and re-run ./start.sh"
exit 1
fi
if ! i2cdetect -y 1 &> /dev/null ; then
echo "i2cdetect -y 1 did not find a screen."
exit 2
fi
if ! test -e venv; then
echo "Creating python venv for OLED Screen"
python3 -m venv venv
echo "Activating venv"
source venv/bin/activate
echo "Installing requirements.txt"
pip install -r requirements.txt
git rev-parse HEAD > current
fi
source venv/bin/activate
# Detect if someone updates - we need to re-run pip install.
if ! test -e current; then
git rev-parse > current
else
if [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
echo "New version detected, updating requirements.txt"
echo " This may take some time..."
pip install wheel
pip install -r requirements.txt
git rev-parse HEAD > current
fi
fi
echo "Starting OLED Screen..."
python3 rascsi_oled_monitor.py

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SASI device controller ]
// [ SASI device controller ]
//
//---------------------------------------------------------------------------
#include "controllers/sasidev_ctrl.h"
@ -37,10 +37,10 @@ SASIDEV::SASIDEV(Device *dev)
{
int i;
#ifndef RASCSI
#ifndef RASCSI
// Remember host device
host = dev;
#endif // RASCSI
#endif // RASCSI
// Work initialization
ctrl.phase = BUS::busfree;
@ -49,9 +49,9 @@ SASIDEV::SASIDEV(Device *dev)
memset(ctrl.cmd, 0x00, sizeof(ctrl.cmd));
ctrl.status = 0x00;
ctrl.message = 0x00;
#ifdef RASCSI
#ifdef RASCSI
ctrl.execstart = 0;
#endif // RASCSI
#endif // RASCSI
ctrl.bufsize = 0x800;
ctrl.buffer = (BYTE *)malloc(ctrl.bufsize);
memset(ctrl.buffer, 0x00, ctrl.bufsize);
@ -96,9 +96,9 @@ void FASTCALL SASIDEV::Reset()
ctrl.phase = BUS::busfree;
ctrl.status = 0x00;
ctrl.message = 0x00;
#ifdef RASCSI
#ifdef RASCSI
ctrl.execstart = 0;
#endif // RASCSI
#endif // RASCSI
memset(ctrl.buffer, 0x00, ctrl.bufsize);
ctrl.blocks = 0;
ctrl.next = 0;
@ -301,9 +301,9 @@ BUS::phase_t FASTCALL SASIDEV::Process()
// For the monitor tool, we shouldn't need to reset. We're just logging information
// Reset
if (ctrl.bus->GetRST()) {
#if defined(DISK_LOG)
Log(Log::Normal, "RESET signal received");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - RESET signal received");
#endif // DISK_LOG
// Reset the controller
Reset();
@ -371,9 +371,9 @@ void FASTCALL SASIDEV::BusFree()
// Phase change
if (ctrl.phase != BUS::busfree) {
#if defined(DISK_LOG)
Log(Log::Normal, "Bus free phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Bus free phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::busfree;
@ -421,10 +421,9 @@ void FASTCALL SASIDEV::Selection()
return;
}
#if defined(DISK_LOG)
Log(Log::Normal,
"Selection Phase ID=%d (with device)", ctrl.id);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SASI - Selection Phase ID=%d (with device)", ctrl.id);
#endif // DISK_LOG
// Phase change
ctrl.phase = BUS::selection;
@ -447,19 +446,19 @@ void FASTCALL SASIDEV::Selection()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Command()
{
#ifdef RASCSI
#ifdef RASCSI
int count;
int i;
#endif // RASCSI
#endif // RASCSI
ASSERT(this);
// Phase change
if (ctrl.phase != BUS::command) {
#if defined(DISK_LOG)
Log(Log::Normal, "Command Phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Command Phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::command;
@ -474,7 +473,7 @@ void FASTCALL SASIDEV::Command()
ctrl.length = 6;
ctrl.blocks = 1;
#ifdef RASCSI
#ifdef RASCSI
// Command reception handshake (10 bytes are automatically received at the first command)
count = ctrl.bus->CommandHandShake(ctrl.buffer);
@ -506,13 +505,13 @@ void FASTCALL SASIDEV::Command()
// Execution Phase
Execute();
#else
#else
// Request the command
ctrl.bus->SetREQ(TRUE);
return;
#endif // RASCSI
#endif // RASCSI
}
#ifndef RASCSI
#ifndef RASCSI
// Requesting
if (ctrl.bus->GetREQ()) {
// Sent by the initiator
@ -525,7 +524,7 @@ void FASTCALL SASIDEV::Command()
ReceiveNext();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -537,9 +536,9 @@ void FASTCALL SASIDEV::Execute()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "Execution Phase Command %02X", ctrl.cmd[0]);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Execution Phase Command %02X", ctrl.cmd[0]);
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::execute;
@ -547,9 +546,9 @@ void FASTCALL SASIDEV::Execute()
// Initialization for data transfer
ctrl.offset = 0;
ctrl.blocks = 1;
#ifdef RASCSI
#ifdef RASCSI
ctrl.execstart = SysTimer::GetTimerLow();
#endif // RASCSI
#endif // RASCSI
// Process by command
switch (ctrl.cmd[0]) {
@ -603,14 +602,25 @@ void FASTCALL SASIDEV::Execute()
CmdAssign();
return;
// RESERVE UNIT(16)
case 0x16:
CmdReserveUnit();
return;
// RELEASE UNIT(17)
case 0x17:
CmdReleaseUnit();
return;
// SPECIFY(SASIのみ)
case 0xc2:
CmdSpecify();
return;
}
// Unsupported command
Log(Log::Warning, "Unsupported command $%02X", ctrl.cmd[0]);
Log(Log::Warning, "SASI - Unsupported command $%02X", ctrl.cmd[0]);
CmdInvalid();
}
@ -621,17 +631,17 @@ void FASTCALL SASIDEV::Execute()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Status()
{
#ifdef RASCSI
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
#endif // RASCSI
ASSERT(this);
// Phase change
if (ctrl.phase != BUS::status) {
#ifdef RASCSI
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -643,11 +653,11 @@ void FASTCALL SASIDEV::Status()
} else {
SysTimer::SleepUsec(5);
}
#endif // RASCSI
#endif // RASCSI
#if defined(DISK_LOG)
Log(Log::Normal, "Status phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Status phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::status;
@ -663,22 +673,22 @@ void FASTCALL SASIDEV::Status()
ctrl.blocks = 1;
ctrl.buffer[0] = (BYTE)ctrl.status;
#ifndef RASCSI
#ifndef RASCSI
// Request status
ctrl.bus->SetDAT(ctrl.buffer[0]);
ctrl.bus->SetREQ(TRUE);
#if defined(DISK_LOG)
Log(Log::Normal, "Status Phase $%02X", ctrl.status);
#endif // DISK_LOG
#endif // RASCSI
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Status Phase $%02X", ctrl.status);
#endif // DISK_LOG
#endif // RASCSI
return;
}
#ifdef RASCSI
#ifdef RASCSI
// Send
Send();
#else
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Initiator received
@ -691,7 +701,7 @@ void FASTCALL SASIDEV::Status()
Send();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -706,9 +716,9 @@ void FASTCALL SASIDEV::MsgIn()
// Phase change
if (ctrl.phase != BUS::msgin) {
#if defined(DISK_LOG)
Log(Log::Normal, "Message in phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Message in phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::msgin;
@ -723,22 +733,22 @@ void FASTCALL SASIDEV::MsgIn()
ASSERT(ctrl.blocks > 0);
ctrl.offset = 0;
#ifndef RASCSI
#ifndef RASCSI
// Request message
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
ctrl.bus->SetREQ(TRUE);
#if defined(DISK_LOG)
Log(Log::Normal, "Message in phase $%02X", ctrl.buffer[ctrl.offset]);
#endif // DISK_LOG
#endif // RASCSI
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Message in phase $%02X", ctrl.buffer[ctrl.offset]);
#endif // DISK_LOG
#endif // RASCSI
return;
}
#ifdef RASCSI
#ifdef RASCSI
//Send
Send();
#else
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Initator received
@ -751,7 +761,7 @@ void FASTCALL SASIDEV::MsgIn()
Send();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -761,10 +771,10 @@ void FASTCALL SASIDEV::MsgIn()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::DataIn()
{
#ifdef RASCSI
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
#endif // RASCSI
ASSERT(this);
ASSERT(ctrl.length >= 0);
@ -772,7 +782,7 @@ void FASTCALL SASIDEV::DataIn()
// Phase change
if (ctrl.phase != BUS::datain) {
#ifdef RASCSI
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -782,7 +792,7 @@ void FASTCALL SASIDEV::DataIn()
}
ctrl.execstart = 0;
}
#endif // RASCSI
#endif // RASCSI
// If the length is 0, go to the status phase
if (ctrl.length == 0) {
@ -790,9 +800,9 @@ void FASTCALL SASIDEV::DataIn()
return;
}
#if defined(DISK_LOG)
Log(Log::Normal, "Data-in Phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Data-in Phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::datain;
@ -807,20 +817,20 @@ void FASTCALL SASIDEV::DataIn()
ASSERT(ctrl.blocks > 0);
ctrl.offset = 0;
#ifndef RASCSI
#ifndef RASCSI
// Assert the DAT signal
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
// Request data
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
#ifdef RASCSI
#ifdef RASCSI
// Send
Send();
#else
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Initator received
@ -833,7 +843,7 @@ void FASTCALL SASIDEV::DataIn()
Send();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -843,10 +853,10 @@ void FASTCALL SASIDEV::DataIn()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::DataOut()
{
#ifdef RASCSI
#ifdef RASCSI
DWORD min_exec_time;
DWORD time;
#endif // RASCSI
#endif // RASCSI
ASSERT(this);
ASSERT(ctrl.length >= 0);
@ -854,7 +864,7 @@ void FASTCALL SASIDEV::DataOut()
// Phase change
if (ctrl.phase != BUS::dataout) {
#ifdef RASCSI
#ifdef RASCSI
// Minimum execution time
if (ctrl.execstart > 0) {
min_exec_time = IsSASI() ? min_exec_time_sasi : min_exec_time_scsi;
@ -864,7 +874,7 @@ void FASTCALL SASIDEV::DataOut()
}
ctrl.execstart = 0;
}
#endif // RASCSI
#endif // RASCSI
// If the length is 0, go to the status phase
if (ctrl.length == 0) {
@ -872,9 +882,9 @@ void FASTCALL SASIDEV::DataOut()
return;
}
#if defined(DISK_LOG)
Log(Log::Normal, "Data out phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Data out phase");
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::dataout;
@ -889,17 +899,17 @@ void FASTCALL SASIDEV::DataOut()
ASSERT(ctrl.blocks > 0);
ctrl.offset = 0;
#ifndef RASCSI
#ifndef RASCSI
// Request data
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
#ifdef RASCSI
#ifdef RASCSI
// Receive
Receive();
#else
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Sent by the initiator
@ -912,7 +922,7 @@ void FASTCALL SASIDEV::DataOut()
ReceiveNext();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -945,9 +955,9 @@ void FASTCALL SASIDEV::Error()
return;
}
#if defined(DISK_LOG)
Log(Log::Warning, "Error occured (going to status phase)");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Warning, "SASI - Error occured (going to status phase)");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -971,9 +981,9 @@ void FASTCALL SASIDEV::CmdTestUnitReady()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "TEST UNIT READY Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - TEST UNIT READY Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1006,9 +1016,9 @@ void FASTCALL SASIDEV::CmdRezero()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "REZERO UNIT Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - REZERO UNIT Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1040,9 +1050,9 @@ void FASTCALL SASIDEV::CmdRequestSense()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "REQUEST SENSE Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - REQUEST SENSE Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1055,9 +1065,9 @@ void FASTCALL SASIDEV::CmdRequestSense()
ctrl.length = ctrl.unit[lun]->RequestSense(ctrl.cmd, ctrl.buffer);
ASSERT(ctrl.length > 0);
#if defined(DISK_LOG)
Log(Log::Normal, "Sense key $%02X", ctrl.buffer[2]);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Sense key $%02X", ctrl.buffer[2]);
#endif // DISK_LOG
// Read phase
DataIn();
@ -1075,9 +1085,9 @@ void FASTCALL SASIDEV::CmdFormat()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "FORMAT UNIT Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - FORMAT UNIT Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1110,9 +1120,9 @@ void FASTCALL SASIDEV::CmdReassign()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "REASSIGN BLOCKS Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - REASSIGN BLOCKS Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1133,6 +1143,42 @@ void FASTCALL SASIDEV::CmdReassign()
Status();
}
// The following commands RESERVE UNIT and RELEASE UNIT are not properly implemented.
// These commands are used in multi-initator environments which this project is not targeted at.
// For now, we simply reply with an OK. -phrax 2021-03-06
//---------------------------------------------------------------------------
//
// RESERVE UNIT(16)
//
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::CmdReserveUnit()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - RESERVE UNIT Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// RELEASE UNIT(17)
//
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::CmdReleaseUnit()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - RELEASE UNIT Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// READ(6)
@ -1163,10 +1209,9 @@ void FASTCALL SASIDEV::CmdRead6()
ctrl.blocks = 0x100;
}
#if defined(DISK_LOG)
Log(Log::Normal,
"READ(6) command record=%06X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SASI - READ(6) command record=%06X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
// Command processing on drive
ctrl.length = ctrl.unit[lun]->Read(ctrl.buffer, record);
@ -1213,10 +1258,9 @@ void FASTCALL SASIDEV::CmdWrite6()
ctrl.blocks = 0x100;
}
#if defined(DISK_LOG)
Log(Log::Normal,
"WRITE(6) command record=%06X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SASI - WRITE(6) command record=%06X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
// Command processing on drive
ctrl.length = ctrl.unit[lun]->WriteCheck(record);
@ -1245,9 +1289,9 @@ void FASTCALL SASIDEV::CmdSeek6()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SEEK(6) Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - SEEK(6) Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1280,9 +1324,9 @@ void FASTCALL SASIDEV::CmdAssign()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "ASSIGN Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - ASSIGN Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1318,9 +1362,9 @@ void FASTCALL SASIDEV::CmdSpecify()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SPECIFY Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - SPECIFY Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1355,9 +1399,9 @@ void FASTCALL SASIDEV::CmdInvalid()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "Command not supported");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Command not supported");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1383,16 +1427,16 @@ void FASTCALL SASIDEV::CmdInvalid()
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Send()
{
#ifdef RASCSI
#ifdef RASCSI
int len;
#endif // RASCSI
#endif // RASCSI
BOOL result;
ASSERT(this);
ASSERT(!ctrl.bus->GetREQ());
ASSERT(ctrl.bus->GetIO());
#ifdef RASCSI
#ifdef RASCSI
// Check that the length isn't 0
if (ctrl.length != 0) {
len = ctrl.bus->SendHandShake(
@ -1409,7 +1453,7 @@ void FASTCALL SASIDEV::Send()
ctrl.length = 0;
return;
}
#else
#else
// Offset and Length
ASSERT(ctrl.length >= 1);
ctrl.offset++;
@ -1422,7 +1466,7 @@ void FASTCALL SASIDEV::Send()
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
#endif // RASCSI
// Remove block and initialize the result
ctrl.blocks--;
@ -1435,9 +1479,9 @@ void FASTCALL SASIDEV::Send()
result = XferIn(ctrl.buffer);
//** printf("xfer in: %d \n",result);
#ifndef RASCSI
#ifndef RASCSI
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
#endif // RASCSI
#endif // RASCSI
}
}
@ -1451,10 +1495,10 @@ void FASTCALL SASIDEV::Send()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
@ -1538,9 +1582,9 @@ void FASTCALL SASIDEV::Receive()
// Command phase
case BUS::command:
ctrl.cmd[ctrl.offset] = data;
#if defined(DISK_LOG)
Log(Log::Normal, "Command phase $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SASI - Command phase $%02X", data);
#endif // DISK_LOG
// Set the length again with the first data (offset 0)
if (ctrl.offset == 0) {
@ -1580,9 +1624,9 @@ void FASTCALL SASIDEV::Receive()
void FASTCALL SASIDEV::ReceiveNext()
#endif // RASCSI
{
#ifdef RASCSI
#ifdef RASCSI
int len;
#endif // RASCSI
#endif // RASCSI
BOOL result;
ASSERT(this);
@ -1591,7 +1635,7 @@ void FASTCALL SASIDEV::ReceiveNext()
ASSERT(!ctrl.bus->GetREQ());
ASSERT(!ctrl.bus->GetIO());
#ifdef RASCSI
#ifdef RASCSI
// Length != 0 if received
if (ctrl.length != 0) {
// Receive
@ -1609,7 +1653,7 @@ void FASTCALL SASIDEV::ReceiveNext()
ctrl.length = 0;
return;
}
#else
#else
// Offset and Length
ASSERT(ctrl.length >= 1);
ctrl.offset++;
@ -1621,7 +1665,7 @@ void FASTCALL SASIDEV::ReceiveNext()
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
#endif // RASCSI
// Remove the control block and initialize the result
ctrl.blocks--;
@ -1648,22 +1692,22 @@ void FASTCALL SASIDEV::ReceiveNext()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
// Move to the next phase
switch (ctrl.phase) {
#ifndef RASCSI
#ifndef RASCSI
// Command phase
case BUS::command:
// Execution Phase
Execute();
break;
#endif // RASCSI
#endif // RASCSI
// Data out phase
case BUS::dataout:
@ -1856,7 +1900,7 @@ void FASTCALL SASIDEV::FlushUnit()
// Debug code related to Issue #2 on github, where we get an unhandled Model select when
// the mac is rebooted
// https://github.com/akuker/RASCSI/issues/2
Log(Log::Warning, "Received \'Mode Select\'\n");
Log(Log::Warning, "SASI - Received \'Mode Select\'\n");
Log(Log::Warning, " Operation Code: [%02X]\n", ctrl.cmd[0]);
Log(Log::Warning, " Logical Unit %01X, PF %01X, SP %01X [%02X]\n", ctrl.cmd[1] >> 5, 1 & (ctrl.cmd[1] >> 4), ctrl.cmd[1] & 1, ctrl.cmd[1]);
Log(Log::Warning, " Reserved: %02X\n", ctrl.cmd[2]);
@ -1868,13 +1912,13 @@ void FASTCALL SASIDEV::FlushUnit()
if (!ctrl.unit[lun]->ModeSelect(
ctrl.cmd, ctrl.buffer, ctrl.offset)) {
// MODE SELECT failed
Log(Log::Warning, "Error occured while processing Mode Select command %02X\n", (unsigned char)ctrl.cmd[0]);
Log(Log::Warning, "SASI - Error occured while processing Mode Select command %02X\n", (unsigned char)ctrl.cmd[0]);
return;
}
break;
default:
Log(Log::Warning, "Received an invalid flush command %02X!!!!!\n",ctrl.cmd[0]);
Log(Log::Warning, "SASI - Received an invalid flush command %02X!!!!!\n",ctrl.cmd[0]);
ASSERT(FALSE);
break;
}
@ -1938,13 +1982,13 @@ void SASIDEV::GetPhaseStr(char *str)
//---------------------------------------------------------------------------
void FASTCALL SASIDEV::Log(Log::loglevel level, const char *format, ...)
{
#if !defined(BAREMETAL)
#ifdef DISK_LOG
#if !defined(BAREMETAL)
#ifdef DISK_LOG
char buffer[0x200];
char buffer2[0x250];
char buffer3[0x250];
char phase_str[20];
#endif
#endif
va_list args;
va_start(args, format);
@ -1953,15 +1997,15 @@ void FASTCALL SASIDEV::Log(Log::loglevel level, const char *format, ...)
return;
}
#ifdef RASCSI
#ifndef DISK_LOG
#ifdef RASCSI
#ifndef DISK_LOG
if (level == Log::Warning) {
return;
}
#endif // DISK_LOG
#endif // RASCSI
#endif // DISK_LOG
#endif // RASCSI
#ifdef DISK_LOG
#ifdef DISK_LOG
// format
vsprintf(buffer, format, args);
@ -1970,30 +2014,28 @@ void FASTCALL SASIDEV::Log(Log::loglevel level, const char *format, ...)
// Add the date/timestamp
// current date/time based on current system
time_t now = time(0);
// convert now to string form
char* dt = ctime(&now);
time_t now = time(0);
// convert now to string form
char* dt = ctime(&now);
strcpy(buffer2, "[");
strcat(buffer2, dt);
// Get rid of the carriage return
buffer2[strlen(buffer2)-1] = '\0';
strcat(buffer2, "] ");
strcpy(buffer2, "[");
strcat(buffer2, dt);
// Get rid of the carriage return
buffer2[strlen(buffer2)-1] = '\0';
strcat(buffer2, "] ");
// Get the phase
this->GetPhaseStr(phase_str);
sprintf(buffer3, "[%d][%s] ", this->GetID(), phase_str);
strcat(buffer2,buffer3);
strcat(buffer2, buffer);
// Get the phase
this->GetPhaseStr(phase_str);
sprintf(buffer3, "[%d][%s] ", this->GetID(), phase_str);
strcat(buffer2,buffer3);
strcat(buffer2, buffer);
// Log output
#ifdef RASCSI
// Log output
#ifdef RASCSI
printf("%s\n", buffer2);
#else
#else
host->GetVM()->GetLog()->Format(level, host, buffer);
#endif // RASCSI
#endif // BAREMETAL
#endif // DISK_LOG
#endif // RASCSI
#endif // BAREMETAL
#endif // DISK_LOG
}

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SASI device controller ]
// [ SASI device controller ]
//
//---------------------------------------------------------------------------
#pragma once
@ -31,181 +31,140 @@
class SASIDEV
{
public:
// Maximum number of logical units
enum {
UnitMax = 8
UnitMax = 8 // Maximum number of logical units
};
#ifdef RASCSI
#ifdef RASCSI
// For timing adjustments
enum {
enum {
min_exec_time_sasi = 100, // SASI BOOT/FORMAT 30:NG 35:OK
min_exec_time_scsi = 50
};
#endif // RASCSI
#endif // RASCSI
// Internal data definition
typedef struct {
// 全般
BUS::phase_t phase; // Transition phase
int id; // Controller ID (0-7)
BUS *bus; // Bus
int id; // Controller ID (0-7)
BUS *bus; // Bus
// commands
DWORD cmd[10]; // Command data
DWORD status; // Status data
DWORD message; // Message data
#ifdef RASCSI
#ifdef RASCSI
// Run
DWORD execstart; // Execution start time
#endif // RASCSI
#endif // RASCSI
// Transfer
BYTE *buffer; // Transfer data buffer
int bufsize; // Transfer data buffer size
DWORD blocks; // Number of transfer block
DWORD next; // Next record
DWORD next; // Next record
DWORD offset; // Transfer offset
DWORD length; // Transfer remaining length
// Logical unit
Disk *unit[UnitMax];
// Logical Unit
Disk *unit[UnitMax]; // Logical Unit
} ctrl_t;
public:
// Basic Functions
#ifdef RASCSI
#ifdef RASCSI
SASIDEV();
#else
SASIDEV(Device *dev);
#endif //RASCSI
#else
// Constructor
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
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
virtual BUS::phase_t FASTCALL Process(); // Run
// Connect
void FASTCALL Connect(int id, BUS *sbus);
// Controller connection
Disk* FASTCALL GetUnit(int no);
// Get logical unit
void FASTCALL SetUnit(int no, Disk *dev);
// Logical unit setting
BOOL FASTCALL HasUnit();
// Has a valid logical unit
void FASTCALL Connect(int id, BUS *sbus); // Controller connection
Disk* FASTCALL GetUnit(int no); // Get logical unit
void FASTCALL SetUnit(int no, Disk *dev); // Logical unit setting
BOOL FASTCALL HasUnit(); // Has a valid logical unit
// Other
BUS::phase_t FASTCALL GetPhase() {return ctrl.phase;}
// Get the phase
#ifdef DISK_LOG
// Function to get the current phase as a String.
void FASTCALL GetPhaseStr(char *str);
#endif
BUS::phase_t FASTCALL GetPhase() {return ctrl.phase;} // Get the phase
#ifdef DISK_LOG
int FASTCALL GetID() {return ctrl.id;}
// Get the ID
void FASTCALL GetCTRL(ctrl_t *buffer);
// Get the internal information
ctrl_t* FASTCALL GetWorkAddr() { return &ctrl; }
// Get the internal information address
virtual BOOL FASTCALL IsSASI() const {return TRUE;}
// SASI Check
virtual BOOL FASTCALL IsSCSI() const {return FALSE;}
// SCSI check
Disk* FASTCALL GetBusyUnit();
// Get the busy unit
// Function to get the current phase as a String.
void FASTCALL GetPhaseStr(char *str);
#endif
int FASTCALL GetID() {return ctrl.id;} // Get the ID
void FASTCALL GetCTRL(ctrl_t *buffer); // Get the internal information
ctrl_t* FASTCALL GetWorkAddr() { return &ctrl; } // Get the internal information address
virtual BOOL FASTCALL IsSASI() const {return TRUE;} // SASI Check
virtual BOOL FASTCALL IsSCSI() const {return FALSE;} // SCSI check
Disk* FASTCALL GetBusyUnit(); // Get the busy unit
protected:
// Phase processing
virtual void FASTCALL BusFree();
// Bus free phase
virtual void FASTCALL Selection();
// Selection phase
virtual void FASTCALL Command();
// Command phase
virtual void FASTCALL Execute();
// Execution phase
void FASTCALL Status();
// Status phase
void FASTCALL MsgIn();
// Message in phase
void FASTCALL DataIn();
// Data in phase
void FASTCALL DataOut();
// Data out phase
virtual void FASTCALL Error();
// Common error handling
virtual void FASTCALL BusFree(); // Bus free phase
virtual void FASTCALL Selection(); // Selection phase
virtual void FASTCALL Command(); // Command phase
virtual void FASTCALL Execute(); // Execution phase
void FASTCALL Status(); // Status phase
void FASTCALL MsgIn(); // Message in phase
void FASTCALL DataIn(); // Data in phase
void FASTCALL DataOut(); // Data out phase
virtual void FASTCALL Error(); // Common error handling
// commands
void FASTCALL CmdTestUnitReady();
// TEST UNIT READY command
void FASTCALL CmdRezero();
// REZERO UNIT command
void FASTCALL CmdRequestSense();
// REQUEST SENSE command
void FASTCALL CmdFormat();
// FORMAT command
void FASTCALL CmdReassign();
// REASSIGN BLOCKS command
void FASTCALL CmdRead6();
// READ(6) command
void FASTCALL CmdWrite6();
// WRITE(6) command
void FASTCALL CmdSeek6();
// SEEK(6) command
void FASTCALL CmdAssign();
// ASSIGN command
void FASTCALL CmdSpecify();
// SPECIFY command
void FASTCALL CmdInvalid();
// Unsupported command
void FASTCALL CmdTestUnitReady(); // TEST UNIT READY command
void FASTCALL CmdRezero(); // REZERO UNIT command
void FASTCALL CmdRequestSense(); // REQUEST SENSE command
void FASTCALL CmdFormat(); // FORMAT command
void FASTCALL CmdReassign(); // REASSIGN BLOCKS command
void FASTCALL CmdReserveUnit(); // RESERVE UNIT command
void FASTCALL CmdReleaseUnit(); // RELEASE UNIT command
void FASTCALL CmdRead6(); // READ(6) command
void FASTCALL CmdWrite6(); // WRITE(6) command
void FASTCALL CmdSeek6(); // SEEK(6) command
void FASTCALL CmdAssign(); // ASSIGN command
void FASTCALL CmdSpecify(); // SPECIFY command
void FASTCALL CmdInvalid(); // Unsupported command
// データ転送
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
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
// Special operations
void FASTCALL FlushUnit();
// Flush the logical unit
void FASTCALL FlushUnit(); // Flush the logical unit
// Log
void FASTCALL Log(Log::loglevel level, const char *format, ...);
// Log output
void FASTCALL Log(Log::loglevel level, const char *format, ...); // Log output
protected:
#ifndef RASCSI
Device *host;
// Host device
#endif // RASCSI
ctrl_t ctrl;
// Internal data
#ifndef RASCSI
Device *host; // Host device
#endif // RASCSI
ctrl_t ctrl; // Internal data
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI device controller ]
// [ SCSI device controller ]
//
//---------------------------------------------------------------------------
#include "controllers/scsidev_ctrl.h"
@ -81,9 +81,9 @@ BUS::phase_t FASTCALL SCSIDEV::Process()
// Reset
if (ctrl.bus->GetRST()) {
#if defined(DISK_LOG)
Log(Log::Normal, "RESET信号受信");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - RESET信号受信");
#endif // DISK_LOG
// Reset the controller
Reset();
@ -162,9 +162,9 @@ void FASTCALL SCSIDEV::BusFree()
// Phase change
if (ctrl.phase != BUS::busfree) {
#if defined(DISK_LOG)
Log(Log::Normal, "Bus free phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Bus free phase");
#endif // DISK_LOG
// Phase setting
ctrl.phase = BUS::busfree;
@ -215,10 +215,9 @@ void FASTCALL SCSIDEV::Selection()
return;
}
#if defined(DISK_LOG)
Log(Log::Normal,
"Selection Phase ID=%d (with device)", ctrl.id);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - Selection Phase ID=%d (with device)", ctrl.id);
#endif // DISK_LOG
// Phase setting
ctrl.phase = BUS::selection;
@ -248,9 +247,9 @@ void FASTCALL SCSIDEV::Execute()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "Execution phase command $%02X", ctrl.cmd[0]);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Execution phase command $%02X", ctrl.cmd[0]);
#endif // DISK_LOG
// Phase Setting
ctrl.phase = BUS::execute;
@ -258,9 +257,9 @@ void FASTCALL SCSIDEV::Execute()
// Initialization for data transfer
ctrl.offset = 0;
ctrl.blocks = 1;
#ifdef RASCSI
#ifdef RASCSI
ctrl.execstart = SysTimer::GetTimerLow();
#endif // RASCSI
#endif // RASCSI
// Process by command
switch (ctrl.cmd[0]) {
@ -314,6 +313,26 @@ void FASTCALL SCSIDEV::Execute()
CmdModeSelect();
return;
// RESERVE(6)
case 0x16:
CmdReserve6();
return;
// RESERVE(10)
case 0x56:
CmdReserve10();
return;
// RELEASE(6)
case 0x17:
CmdRelease6();
return;
// RELEASE(10)
case 0x57:
CmdRelease10();
return;
// MDOE SENSE
case 0x1a:
CmdModeSense();
@ -412,7 +431,7 @@ void FASTCALL SCSIDEV::Execute()
}
// No other support
Log(Log::Normal, "Unsupported command received: $%02X", ctrl.cmd[0]);
Log(Log::Normal, "SCSI - Unsupported command received: $%02X", ctrl.cmd[0]);
CmdInvalid();
}
@ -428,12 +447,11 @@ void FASTCALL SCSIDEV::MsgOut()
// Phase change
if (ctrl.phase != BUS::msgout) {
#if defined(DISK_LOG)
Log(Log::Normal, "Message Out Phase");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Message Out Phase"); // Message out phase after selection
#endif // DISK_LOG
// Message out phase after selection
// process the IDENTIFY message
// process the IDENTIFY message
if (ctrl.phase == BUS::selection) {
scsi.atnmsg = TRUE;
scsi.msc = 0;
@ -453,17 +471,18 @@ void FASTCALL SCSIDEV::MsgOut()
ctrl.length = 1;
ctrl.blocks = 1;
#ifndef RASCSI
#ifndef RASCSI
// Request message
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
#ifdef RASCSI
#ifdef RASCSI
// Receive
Receive();
#else
#else
// Requesting
if (ctrl.bus->GetREQ()) {
// Sent by the initiator
@ -476,7 +495,7 @@ void FASTCALL SCSIDEV::MsgOut()
ReceiveNext();
}
}
#endif // RASCSI
#endif // RASCSI
}
//---------------------------------------------------------------------------
@ -507,9 +526,9 @@ void FASTCALL SCSIDEV::Error()
return;
}
#if defined(DISK_LOG)
Log(Log::Normal, "Error (to status phase)");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Error (to status phase)");
#endif // DISK_LOG
// Set status and message(CHECK CONDITION)
ctrl.status = 0x02;
@ -539,9 +558,9 @@ void FASTCALL SCSIDEV::CmdInquiry()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "INQUIRY Command");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - INQUIRY Command");
#endif // DISK_LOG
// Find a valid unit
disk = NULL;
@ -588,9 +607,9 @@ void FASTCALL SCSIDEV::CmdModeSelect()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "MODE SELECT Command");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - MODE SELECT Command");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -611,6 +630,75 @@ void FASTCALL SCSIDEV::CmdModeSelect()
DataOut();
}
// The following commands RESERVE(6), RESERVE(10), RELEASE(6) and RELEASE(10)
// are not properly implemented. These commands are used in multi-initator environments
// which this project is not targeted at. For now, we simply reply with an OK.
// -phrax 2021-03-06
//---------------------------------------------------------------------------
//
// RESERVE(6)
//
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::CmdReserve6()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - RESERVE(6) Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// RESERVE(10)
//
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::CmdReserve10()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - RESERVE(10) Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// RELEASE(6)
//
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::CmdRelease6()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - RELEASE(6) Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// RELEASE(10)
//
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::CmdRelease10()
{
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - RELEASE(10) Command");
#endif // DISK_LOG
// status phase
Status();
}
//---------------------------------------------------------------------------
//
// MODE SENSE
@ -622,9 +710,9 @@ void FASTCALL SCSIDEV::CmdModeSense()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "MODE SENSE Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - MODE SENSE Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -637,8 +725,7 @@ void FASTCALL SCSIDEV::CmdModeSense()
ctrl.length = ctrl.unit[lun]->ModeSense(ctrl.cmd, ctrl.buffer);
ASSERT(ctrl.length >= 0);
if (ctrl.length == 0) {
Log(Log::Warning,
"Not supported MODE SENSE page $%02X", ctrl.cmd[2]);
Log(Log::Warning,"SCSI - Not supported MODE SENSE page $%02X", ctrl.cmd[2]);
// Failure (Error)
Error();
@ -661,9 +748,9 @@ void FASTCALL SCSIDEV::CmdStartStop()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "START STOP UNIT Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - START STOP UNIT Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -696,9 +783,9 @@ void FASTCALL SCSIDEV::CmdSendDiag()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SEND DIAGNOSTIC Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - SEND DIAGNOSTIC Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -731,9 +818,9 @@ void FASTCALL SCSIDEV::CmdRemoval()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "PREVENT/ALLOW MEDIUM REMOVAL Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - PREVENT/ALLOW MEDIUM REMOVAL Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -766,9 +853,9 @@ void FASTCALL SCSIDEV::CmdReadCapacity()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "READ CAPACITY Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - READ CAPACITY Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -829,9 +916,9 @@ void FASTCALL SCSIDEV::CmdRead10()
ctrl.blocks <<= 8;
ctrl.blocks |= ctrl.cmd[8];
#if defined(DISK_LOG)
Log(Log::Normal, "READ(10) command record=%08X block=%d", record, ctrl.blocks);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - READ(10) command record=%08X block=%d", record, ctrl.blocks);
#endif // DISK_LOG
// Do not process 0 blocks
if (ctrl.blocks == 0) {
@ -891,10 +978,9 @@ void FASTCALL SCSIDEV::CmdWrite10()
ctrl.blocks <<= 8;
ctrl.blocks |= ctrl.cmd[8];
#if defined(DISK_LOG)
Log(Log::Normal,
"WRTIE(10) command record=%08X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - WRTIE(10) command record=%08X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
// Do not process 0 blocks
if (ctrl.blocks == 0) {
@ -929,9 +1015,9 @@ void FASTCALL SCSIDEV::CmdSeek10()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "SEEK(10) Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - SEEK(10) Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -984,10 +1070,9 @@ void FASTCALL SCSIDEV::CmdVerify()
ctrl.blocks <<= 8;
ctrl.blocks |= ctrl.cmd[8];
#if defined(DISK_LOG)
Log(Log::Normal,
"VERIFY command record=%08X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - VERIFY command record=%08X blocks=%d", record, ctrl.blocks);
#endif // DISK_LOG
// Do not process 0 blocks
if (ctrl.blocks == 0) {
@ -1057,12 +1142,11 @@ void FASTCALL SCSIDEV::CmdSynchronizeCache()
void FASTCALL SCSIDEV::CmdReadDefectData10()
{
DWORD lun;
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "READ DEFECT DATA(10) Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - READ DEFECT DATA(10) Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1092,7 +1176,6 @@ void FASTCALL SCSIDEV::CmdReadDefectData10()
void FASTCALL SCSIDEV::CmdReadToc()
{
DWORD lun;
ASSERT(this);
// Logical Unit
@ -1218,9 +1301,9 @@ void FASTCALL SCSIDEV::CmdModeSelect10()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "MODE SELECT10 Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - MODE SELECT10 Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1252,9 +1335,9 @@ void FASTCALL SCSIDEV::CmdModeSense10()
ASSERT(this);
#if defined(DISK_LOG)
Log(Log::Normal, "MODE SENSE(10) Command ");
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - MODE SENSE(10) Command ");
#endif // DISK_LOG
// Logical Unit
lun = (ctrl.cmd[1] >> 5) & 0x07;
@ -1267,8 +1350,7 @@ void FASTCALL SCSIDEV::CmdModeSense10()
ctrl.length = ctrl.unit[lun]->ModeSense10(ctrl.cmd, ctrl.buffer);
ASSERT(ctrl.length >= 0);
if (ctrl.length == 0) {
Log(Log::Warning,
"Not supported MODE SENSE(10) page $%02X", ctrl.cmd[2]);
Log(Log::Warning,"SCSI - Not supported MODE SENSE(10) page $%02X", ctrl.cmd[2]);
// Failure (Error)
Error();
@ -1394,16 +1476,16 @@ void FASTCALL SCSIDEV::CmdSendMessage10()
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::Send()
{
#ifdef RASCSI
#ifdef RASCSI
int len;
#endif // RASCSI
#endif // RASCSI
BOOL result;
ASSERT(this);
ASSERT(!ctrl.bus->GetREQ());
ASSERT(ctrl.bus->GetIO());
#ifdef RASCSI
#ifdef RASCSI
//if Length! = 0, send
if (ctrl.length != 0) {
len = ctrl.bus->SendHandShake(
@ -1420,20 +1502,20 @@ void FASTCALL SCSIDEV::Send()
ctrl.length = 0;
return;
}
#else
#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) {
// set by SendNext, raise the request
if (ctrl.length != 0) {
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
#endif // RASCSI
// Block subtraction, result initialization
ctrl.blocks--;
@ -1442,11 +1524,11 @@ void FASTCALL SCSIDEV::Send()
// Processing after data collection (read/data-in only)
if (ctrl.phase == BUS::datain) {
if (ctrl.blocks != 0) {
// // set next buffer (set offset, length)
// set next buffer (set offset, length)
result = XferIn(ctrl.buffer);
#ifndef RASCSI
#ifndef RASCSI
ctrl.bus->SetDAT(ctrl.buffer[ctrl.offset]);
#endif // RASCSI
#endif // RASCSI
}
}
@ -1460,10 +1542,10 @@ void FASTCALL SCSIDEV::Send()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
@ -1556,9 +1638,9 @@ void FASTCALL SCSIDEV::Receive()
// Command phase
case BUS::command:
ctrl.cmd[ctrl.offset] = data;
#if defined(DISK_LOG)
Log(Log::Normal, "Command phase $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Command phase $%02X", data);
#endif // DISK_LOG
// Set the length again with the first data (offset 0)
if (ctrl.offset == 0) {
@ -1572,9 +1654,9 @@ void FASTCALL SCSIDEV::Receive()
// Message out phase
case BUS::msgout:
ctrl.message = data;
#if defined(DISK_LOG)
Log(Log::Normal, "Message out phase $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Message out phase $%02X", data);
#endif // DISK_LOG
break;
// Data out phase
@ -1598,6 +1680,7 @@ void FASTCALL SCSIDEV::Receive()
//---------------------------------------------------------------------------
void FASTCALL SCSIDEV::Receive()
#else
//---------------------------------------------------------------------------
//
// Continue receiving data
@ -1606,9 +1689,9 @@ void FASTCALL SCSIDEV::Receive()
void FASTCALL SCSIDEV::ReceiveNext()
#endif // RASCSI
{
#ifdef RASCSI
#ifdef RASCSI
int len;
#endif // RASCSI
#endif // RASCSI
BOOL result;
int i;
BYTE data;
@ -1619,7 +1702,7 @@ void FASTCALL SCSIDEV::ReceiveNext()
ASSERT(!ctrl.bus->GetREQ());
ASSERT(!ctrl.bus->GetIO());
#ifdef RASCSI
#ifdef RASCSI
// Length != 0 if received
if (ctrl.length != 0) {
// Receive
@ -1637,7 +1720,7 @@ void FASTCALL SCSIDEV::ReceiveNext()
ctrl.length = 0;;
return;
}
#else
#else
// Offset and Length
ASSERT(ctrl.length >= 1);
ctrl.offset++;
@ -1649,7 +1732,7 @@ void FASTCALL SCSIDEV::ReceiveNext()
ctrl.bus->SetREQ(TRUE);
return;
}
#endif // RASCSI
#endif // RASCSI
// Block subtraction, result initialization
ctrl.blocks--;
@ -1696,10 +1779,10 @@ void FASTCALL SCSIDEV::ReceiveNext()
if (ctrl.blocks != 0){
ASSERT(ctrl.length > 0);
ASSERT(ctrl.offset == 0);
#ifndef RASCSI
#ifndef RASCSI
// Signal line operated by the target
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
@ -1707,7 +1790,7 @@ void FASTCALL SCSIDEV::ReceiveNext()
switch (ctrl.phase) {
// Command phase
case BUS::command:
#ifdef RASCSI
#ifdef RASCSI
// Command data transfer
len = 6;
if (ctrl.buffer[0] >= 0x20 && ctrl.buffer[0] <= 0x7D) {
@ -1716,11 +1799,11 @@ void FASTCALL SCSIDEV::ReceiveNext()
}
for (i = 0; i < len; i++) {
ctrl.cmd[i] = (DWORD)ctrl.buffer[i];
#if defined(DISK_LOG)
Log(Log::Normal, "Command $%02X", ctrl.cmd[i]);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal, "SCSI - Command $%02X", ctrl.cmd[i]);
#endif // DISK_LOG
}
#endif // RASCSI
#endif // RASCSI
// Execution Phase
Execute();
@ -1734,10 +1817,10 @@ void FASTCALL SCSIDEV::ReceiveNext()
ctrl.offset = 0;
ctrl.length = 1;
ctrl.blocks = 1;
#ifndef RASCSI
#ifndef RASCSI
// Request message
ctrl.bus->SetREQ(TRUE);
#endif // RASCSI
#endif // RASCSI
return;
}
@ -1750,20 +1833,18 @@ void FASTCALL SCSIDEV::ReceiveNext()
// ABORT
if (data == 0x06) {
#if defined(DISK_LOG)
Log(Log::Normal,
"Message code ABORT $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - Message code ABORT $%02X", data);
#endif // DISK_LOG
BusFree();
return;
}
// BUS DEVICE RESET
if (data == 0x0C) {
#if defined(DISK_LOG)
Log(Log::Normal,
"Message code BUS DEVICE RESET $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - Message code BUS DEVICE RESET $%02X", data);
#endif // DISK_LOG
scsi.syncoffset = 0;
BusFree();
return;
@ -1771,18 +1852,16 @@ void FASTCALL SCSIDEV::ReceiveNext()
// IDENTIFY
if (data >= 0x80) {
#if defined(DISK_LOG)
Log(Log::Normal,
"Message code IDENTIFY $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - Message code IDENTIFY $%02X", data);
#endif // DISK_LOG
}
// Extended Message
if (data == 0x01) {
#if defined(DISK_LOG)
Log(Log::Normal,
"Message code EXTENDED MESSAGE $%02X", data);
#endif // DISK_LOG
#if defined(DISK_LOG)
Log(Log::Normal,"SCSI - Message code EXTENDED MESSAGE $%02X", data);
#endif // DISK_LOG
// Check only when synchronous transfer is possible
if (!scsi.syncenable || scsi.msb[i + 2] != 0x01) {

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI device controller ]
// [ SCSI device controller ]
//
//---------------------------------------------------------------------------
#pragma once
@ -43,100 +43,66 @@ public:
#ifdef RASCSI
SCSIDEV();
#else
SCSIDEV(Device *dev);
SCSIDEV(Device *dev); // Constructor
#endif // RASCSI
// Constructor
void FASTCALL Reset();
// Device Reset
void FASTCALL Reset(); // Device Reset
// 外部API
BUS::phase_t FASTCALL Process();
// Run
BUS::phase_t FASTCALL Process(); // Run
void FASTCALL SyncTransfer(BOOL enable) { scsi.syncenable = enable; }
// Synchronouse transfer enable setting
void FASTCALL SyncTransfer(BOOL enable) { scsi.syncenable = enable; } // Synchronouse transfer enable setting
// Other
BOOL FASTCALL IsSASI() const {return FALSE;}
// SASI Check
BOOL FASTCALL IsSCSI() const {return TRUE;}
// SCSI check
BOOL FASTCALL IsSASI() const {return FALSE;} // SASI Check
BOOL FASTCALL IsSCSI() const {return TRUE;} // SCSI check
private:
// Phase
void FASTCALL BusFree();
// Bus free phase
void FASTCALL Selection();
// Selection phase
void FASTCALL Execute();
// Execution phase
void FASTCALL MsgOut();
// Message out phase
void FASTCALL Error();
// Common erorr handling
void FASTCALL BusFree(); // Bus free phase
void FASTCALL Selection(); // Selection phase
void FASTCALL Execute(); // Execution phase
void FASTCALL MsgOut(); // Message out phase
void FASTCALL Error(); // Common erorr handling
// commands
void FASTCALL CmdInquiry();
// INQUIRY command
void FASTCALL CmdModeSelect();
// MODE SELECT command
void FASTCALL CmdModeSense();
// MODE SENSE command
void FASTCALL CmdStartStop();
// START STOP UNIT command
void FASTCALL CmdSendDiag();
// SEND DIAGNOSTIC command
void FASTCALL CmdRemoval();
// PREVENT/ALLOW MEDIUM REMOVAL command
void FASTCALL CmdReadCapacity();
// READ CAPACITY command
void FASTCALL CmdRead10();
// READ(10) command
void FASTCALL CmdWrite10();
// WRITE(10) command
void FASTCALL CmdSeek10();
// SEEK(10) command
void FASTCALL CmdVerify();
// VERIFY command
void FASTCALL CmdSynchronizeCache();
// SYNCHRONIZE CACHE command
void FASTCALL CmdReadDefectData10();
// READ DEFECT DATA(10) command
void FASTCALL CmdReadToc();
// READ TOC command
void FASTCALL CmdPlayAudio10();
// PLAY AUDIO(10) command
void FASTCALL CmdPlayAudioMSF();
// PLAY AUDIO MSF command
void FASTCALL CmdPlayAudioTrack();
// PLAY AUDIO TRACK INDEX command
void FASTCALL CmdModeSelect10();
// MODE SELECT(10) command
void FASTCALL CmdModeSense10();
// MODE SENSE(10) command
void FASTCALL CmdGetMessage10();
// GET MESSAGE(10) command
void FASTCALL CmdSendMessage10();
// SEND MESSAGE(10) command
void FASTCALL CmdInquiry(); // INQUIRY command
void FASTCALL CmdModeSelect(); // MODE SELECT command
void FASTCALL CmdReserve6(); // RESERVE(6) command
void FASTCALL CmdReserve10(); // RESERVE(10) command
void FASTCALL CmdRelease6(); // RELEASE(6) command
void FASTCALL CmdRelease10(); // RELEASE(10) command
void FASTCALL CmdModeSense(); // MODE SENSE command
void FASTCALL CmdStartStop(); // START STOP UNIT command
void FASTCALL CmdSendDiag(); // SEND DIAGNOSTIC command
void FASTCALL CmdRemoval(); // PREVENT/ALLOW MEDIUM REMOVAL command
void FASTCALL CmdReadCapacity(); // READ CAPACITY command
void FASTCALL CmdRead10(); // READ(10) command
void FASTCALL CmdWrite10(); // WRITE(10) command
void FASTCALL CmdSeek10(); // SEEK(10) command
void FASTCALL CmdVerify(); // VERIFY command
void FASTCALL CmdSynchronizeCache(); // SYNCHRONIZE CACHE command
void FASTCALL CmdReadDefectData10(); // READ DEFECT DATA(10) command
void FASTCALL CmdReadToc(); // READ TOC command
void FASTCALL CmdPlayAudio10(); // PLAY AUDIO(10) command
void FASTCALL CmdPlayAudioMSF(); // PLAY AUDIO MSF command
void FASTCALL CmdPlayAudioTrack(); // PLAY AUDIO TRACK INDEX command
void FASTCALL CmdModeSelect10(); // MODE SELECT(10) command
void FASTCALL CmdModeSense10(); // MODE SENSE(10) command
void FASTCALL CmdGetMessage10(); // GET MESSAGE(10) command
void FASTCALL CmdSendMessage10(); // SEND MESSAGE(10) 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
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
scsi_t scsi; // Internal data
};

File diff suppressed because it is too large Load Diff

View File

@ -28,26 +28,17 @@ class CTapDriver
{
public:
// Basic Functionality
CTapDriver();
// Constructor
BOOL FASTCALL Init();
// Initilization
void FASTCALL Cleanup();
// Cleanup
void FASTCALL GetMacAddr(BYTE *mac);
// Get Mac Address
int FASTCALL Rx(BYTE *buf);
// Receive
int FASTCALL Tx(BYTE *buf, int len);
// Send
CTapDriver(); // Constructor
BOOL FASTCALL Init(); // Initilization
void FASTCALL Cleanup(); // Cleanup
void FASTCALL GetMacAddr(BYTE *mac); // Get Mac Address
int FASTCALL Rx(BYTE *buf); // Receive
int FASTCALL Tx(BYTE *buf, int len); // Send
private:
BYTE m_MacAddr[6];
// MAC Address
BOOL m_bTxValid;
// Send Valid Flag
int m_hTAP;
// File handle
BYTE m_MacAddr[6]; // MAC Address
BOOL m_bTxValid; // Send Valid Flag
int m_hTAP; // File handle
};
#endif // ctapdriver_h

View File

@ -11,7 +11,7 @@
//
// Imported sava's Anex86/T98Next image and MO format support patch.
// Imported NetBSD support and some optimisation patch by Rin Okuyama.
// Comments translated to english by akuker.
// Comments translated to english by akuker.
//
// [ Disk ]
//
@ -161,11 +161,11 @@ BOOL FASTCALL DiskTrack::Load(const Filepath& path)
ASSERT((dt.sectors > 0) && (dt.sectors <= 0x100));
if (dt.buffer == NULL) {
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
posix_memalign((void **)&dt.buffer, 512, ((length + 511) / 512) * 512);
#else
#else
dt.buffer = (BYTE *)malloc(length * sizeof(BYTE));
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
dt.length = length;
}
@ -176,11 +176,11 @@ 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 defined(RASCSI) && !defined(BAREMETAL)
posix_memalign((void **)&dt.buffer, 512, ((length + 511) / 512) * 512);
#else
#else
dt.buffer = (BYTE *)malloc(length * sizeof(BYTE));
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
dt.length = length;
}
@ -205,11 +205,11 @@ BOOL FASTCALL DiskTrack::Load(const Filepath& path)
memset(dt.changemap, 0x00, dt.sectors * sizeof(BOOL));
// Read from File
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
if (!fio.OpenDIO(path, Fileio::ReadOnly)) {
#else
#else
if (!fio.Open(path, Fileio::ReadOnly)) {
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
return FALSE;
}
if (dt.raw) {
@ -1653,7 +1653,7 @@ int FASTCALL Disk::AddFormat(BOOL change, BYTE *buf)
buf[1] = 0x16;
// Show the number of bytes in the physical sector as changeable
// (though it cannot be changed in practice)
// (though it cannot be changed in practice)
if (change) {
buf[0xc] = 0xff;
buf[0xd] = 0xff;
@ -1815,7 +1815,7 @@ int FASTCALL Disk::AddCDDA(BOOL change, BYTE *buf)
}
// Audio waits for operation completion and allows
// PLAY across multiple tracks
// PLAY across multiple tracks
return 16;
}

View File

@ -8,8 +8,8 @@
// XM6i
// Copyright (C) 2010-2015 isaki@NetBSD.org
//
// Imported sava's Anex86/T98Next image and MO format support patch.
// Comments translated to english by akuker.
// Imported sava's Anex86/T98Next image and MO format support patch.
// Comments translated to english by akuker.
//
// [ Disk ]
//
@ -62,11 +62,11 @@
#ifdef RASCSI
#define BENDER_SIGNATURE "RaSCSI"
#define BENDER_SIGNATURE "RaSCSI"
// The following line was to mimic Apple's CDROM ID
// #define BENDER_SIGNATURE "SONY "
#else
#define BENDER_SIGNATURE "XM6"
#define BENDER_SIGNATURE "XM6"
#endif
//===========================================================================
@ -79,49 +79,38 @@ class DiskTrack
public:
// Internal data definition
typedef struct {
int track; // Track Number
int size; // Sector Size(8 or 9)
int sectors; // Number of sectors(<=0x100)
DWORD length; // Data buffer length
BYTE *buffer; // Data buffer
BOOL init; // Is it initilized?
BOOL changed; // Changed flag
DWORD maplen; // Changed map length
BOOL *changemap; // Changed map
BOOL raw; // RAW mode flag
off64_t imgoffset; // Offset to actual data
int track; // Track Number
int size; // Sector Size(8 or 9)
int sectors; // Number of sectors(<=0x100)
DWORD length; // Data buffer length
BYTE *buffer; // Data buffer
BOOL init; // Is it initilized?
BOOL changed; // Changed flag
DWORD maplen; // Changed map length
BOOL *changemap; // Changed map
BOOL raw; // RAW mode flag
off64_t imgoffset; // Offset to actual data
} disktrk_t;
public:
// Basic Functions
DiskTrack();
// Constructor
virtual ~DiskTrack();
// Destructor
void FASTCALL Init(int track, int size, int sectors, BOOL raw = FALSE,
off64_t imgoff = 0);
// Initialization
BOOL FASTCALL Load(const Filepath& path);
// Load
BOOL FASTCALL Save(const Filepath& path);
// Save
DiskTrack(); // Constructor
virtual ~DiskTrack(); // Destructor
void FASTCALL Init(int track, int size, int sectors, BOOL raw = FALSE, off64_t imgoff = 0);// Initialization
BOOL FASTCALL Load(const Filepath& path); // Load
BOOL FASTCALL Save(const Filepath& path); // Save
// Read / Write
BOOL FASTCALL Read(BYTE *buf, int sec) const;
// Sector Read
BOOL FASTCALL Write(const BYTE *buf, int sec);
// Sector Write
BOOL FASTCALL Read(BYTE *buf, int sec) const; // Sector Read
BOOL FASTCALL Write(const BYTE *buf, int sec); // Sector Write
// Other
int FASTCALL GetTrack() const { return dt.track; }
// Get track
BOOL FASTCALL IsChanged() const { return dt.changed; }
// Changed flag check
int FASTCALL GetTrack() const { return dt.track; } // Get track
BOOL FASTCALL IsChanged() const { return dt.changed; } // Changed flag check
private:
// Internal data
disktrk_t dt;
// Internal data
disktrk_t dt; // Internal data
};
//===========================================================================
@ -134,61 +123,42 @@ class DiskCache
public:
// Internal data definition
typedef struct {
DiskTrack *disktrk; // Disk Track
DWORD serial; // Serial
DiskTrack *disktrk; // Disk Track
DWORD serial; // Serial
} cache_t;
// Number of caches
enum {
CacheMax = 16 // Number of tracks to cache
CacheMax = 16 // Number of tracks to cache
};
public:
// Basic Functions
DiskCache(const Filepath& path, int size, int blocks,
off64_t imgoff = 0);
// Constructor
virtual ~DiskCache();
// Destructor
void FASTCALL SetRawMode(BOOL raw);
// CD-ROM raw mode setting
DiskCache(const Filepath& path, int size, int blocks,off64_t imgoff = 0);// Constructor
virtual ~DiskCache(); // Destructor
void FASTCALL SetRawMode(BOOL raw); // CD-ROM raw mode setting
// Access
BOOL FASTCALL Save();
// Save and release all
BOOL FASTCALL Read(BYTE *buf, int block);
// Sector Read
BOOL FASTCALL Write(const BYTE *buf, int block);
// Sector Write
BOOL FASTCALL GetCache(int index, int& track, DWORD& serial) const;
// Get cache information
BOOL FASTCALL Save(); // Save and release all
BOOL FASTCALL Read(BYTE *buf, int block); // Sector Read
BOOL FASTCALL Write(const BYTE *buf, int block); // Sector Write
BOOL FASTCALL GetCache(int index, int& track, DWORD& serial) const; // Get cache information
private:
// Internal Management
void FASTCALL Clear();
// Clear all tracks
DiskTrack* FASTCALL Assign(int track);
// Load track
BOOL FASTCALL Load(int index, int track, DiskTrack *disktrk = NULL);
// Load track
void FASTCALL Update();
// Update serial number
void FASTCALL Clear(); // Clear all tracks
DiskTrack* FASTCALL Assign(int track); // Load track
BOOL FASTCALL Load(int index, int track, DiskTrack *disktrk = NULL); // Load track
void FASTCALL Update(); // Update serial number
// Internal data
cache_t cache[CacheMax];
// Cache management
DWORD serial;
// Last serial number
Filepath sec_path;
// Path
int sec_size;
// Sector size (8 or 9 or 11)
int sec_blocks;
// Blocks per sector
BOOL cd_raw;
// CD-ROM RAW mode
off64_t imgoffset;
// Offset to actual data
cache_t cache[CacheMax]; // Cache management
DWORD serial; // Last serial number
Filepath sec_path; // Path
int sec_size; // Sector size (8 or 9 or 11)
int sec_blocks; // Blocks per sector
BOOL cd_raw; // CD-ROM RAW mode
off64_t imgoffset; // Offset to actual data
};
//===========================================================================
@ -201,168 +171,104 @@ class Disk
public:
// Internal data structure
typedef struct {
DWORD id; // Media ID
BOOL ready; // Valid Disk
BOOL writep; // Write protected
BOOL readonly; // Read only
BOOL removable; // Removable
BOOL lock; // Locked
BOOL attn; // Attention
BOOL reset; // Reset
int size; // Sector Size
DWORD blocks; // Total number of sectors
DWORD lun; // LUN
DWORD code; // Status code
DiskCache *dcache; // Disk cache
off64_t imgoffset; // Offset to actual data
DWORD id; // Media ID
BOOL ready; // Valid Disk
BOOL writep; // Write protected
BOOL readonly; // Read only
BOOL removable; // Removable
BOOL lock; // Locked
BOOL attn; // Attention
BOOL reset; // Reset
int size; // Sector Size
DWORD blocks; // Total number of sectors
DWORD lun; // LUN
DWORD code; // Status code
DiskCache *dcache; // Disk cache
off64_t imgoffset; // Offset to actual data
} disk_t;
public:
// Basic Functions
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
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 { return disk.id; }
// Get media ID
BOOL FASTCALL IsNULL() const;
// NULL check
BOOL FASTCALL IsSASI() const;
// SASI Check
BOOL FASTCALL IsSCSI() const;
// SASI Check
DWORD FASTCALL GetID() const { return disk.id; } // Get media ID
BOOL FASTCALL IsNULL() const; // NULL check
BOOL FASTCALL IsSASI() const; // SASI Check
BOOL FASTCALL IsSCSI() const; // SASI Check
// Media Operations
virtual BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE);
// Open
void FASTCALL GetPath(Filepath& path) const;
// Get the path
void FASTCALL Eject(BOOL force);
// Eject
BOOL FASTCALL IsReady() const { return disk.ready; }
// Ready check
void FASTCALL WriteP(BOOL flag);
// Set Write Protect flag
BOOL FASTCALL IsWriteP() const { return disk.writep; }
// Get write protect flag
BOOL FASTCALL IsReadOnly() const { return disk.readonly; }
// Get read only flag
BOOL FASTCALL IsRemovable() const { return disk.removable; }
// Get is removable flag
BOOL FASTCALL IsLocked() const { return disk.lock; }
// Get locked status
BOOL FASTCALL IsAttn() const { return disk.attn; }
// Get attention flag
BOOL FASTCALL Flush();
// Flush the cache
void FASTCALL GetDisk(disk_t *buffer) const;
// Get the internal data struct
virtual BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
void FASTCALL GetPath(Filepath& path) const; // Get the path
void FASTCALL Eject(BOOL force); // Eject
BOOL FASTCALL IsReady() const { return disk.ready; } // Ready check
void FASTCALL WriteP(BOOL flag); // Set Write Protect flag
BOOL FASTCALL IsWriteP() const { return disk.writep; } // Get write protect flag
BOOL FASTCALL IsReadOnly() const { return disk.readonly; } // Get read only flag
BOOL FASTCALL IsRemovable() const { return disk.removable; } // Get is removable flag
BOOL FASTCALL IsLocked() const { return disk.lock; } // Get locked status
BOOL FASTCALL IsAttn() const { return disk.attn; } // Get attention flag
BOOL FASTCALL Flush(); // Flush the cache
void FASTCALL GetDisk(disk_t *buffer) const; // Get the internal data struct
// Properties
void FASTCALL SetLUN(DWORD lun) { disk.lun = lun; }
// LUN set
DWORD FASTCALL GetLUN() { return disk.lun; }
// LUN get
void FASTCALL SetLUN(DWORD lun) { disk.lun = lun; } // LUN set
DWORD FASTCALL GetLUN() { return disk.lun; } // LUN get
// commands
virtual int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);
// INQUIRY command
virtual int FASTCALL RequestSense(const DWORD *cdb, BYTE *buf);
// REQUEST SENSE command
int FASTCALL SelectCheck(const DWORD *cdb);
// SELECT check
int FASTCALL SelectCheck10(const DWORD *cdb);
// SELECT(10) check
virtual BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length);
// MODE SELECT command
virtual int FASTCALL ModeSense(const DWORD *cdb, BYTE *buf);
// MODE SENSE command
virtual int FASTCALL ModeSense10(const DWORD *cdb, BYTE *buf);
// MODE SENSE(10) command
int FASTCALL ReadDefectData10(const DWORD *cdb, BYTE *buf);
// READ DEFECT DATA(10) command
virtual BOOL FASTCALL TestUnitReady(const DWORD *cdb);
// TEST UNIT READY command
BOOL FASTCALL Rezero(const DWORD *cdb);
// REZERO command
BOOL FASTCALL Format(const DWORD *cdb);
// FORMAT UNIT command
BOOL FASTCALL Reassign(const DWORD *cdb);
// REASSIGN UNIT command
virtual int FASTCALL Read(BYTE *buf, DWORD block);
// READ command
int FASTCALL WriteCheck(DWORD block);
// WRITE check
BOOL FASTCALL Write(const BYTE *buf, DWORD block);
// WRITE command
BOOL FASTCALL Seek(const DWORD *cdb);
// SEEK command
BOOL FASTCALL Assign(const DWORD *cdb);
// ASSIGN command
BOOL FASTCALL Specify(const DWORD *cdb);
// SPECIFY command
BOOL FASTCALL StartStop(const DWORD *cdb);
// START STOP UNIT command
BOOL FASTCALL SendDiag(const DWORD *cdb);
// SEND DIAGNOSTIC command
BOOL FASTCALL Removal(const DWORD *cdb);
// PREVENT/ALLOW MEDIUM REMOVAL command
int FASTCALL ReadCapacity(const DWORD *cdb, BYTE *buf);
// READ CAPACITY command
BOOL FASTCALL Verify(const DWORD *cdb);
// VERIFY command
virtual int FASTCALL ReadToc(const DWORD *cdb, BYTE *buf);
// READ TOC command
virtual BOOL FASTCALL PlayAudio(const DWORD *cdb);
// PLAY AUDIO command
virtual BOOL FASTCALL PlayAudioMSF(const DWORD *cdb);
// PLAY AUDIO MSF command
virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb);
// PLAY AUDIO TRACK command
void FASTCALL InvalidCmd() { disk.code = DISK_INVALIDCMD; }
// Unsupported command
virtual int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);// INQUIRY command
virtual int FASTCALL RequestSense(const DWORD *cdb, BYTE *buf); // REQUEST SENSE command
int FASTCALL SelectCheck(const DWORD *cdb); // SELECT check
int FASTCALL SelectCheck10(const DWORD *cdb); // SELECT(10) check
virtual BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length);// MODE SELECT command
virtual int FASTCALL ModeSense(const DWORD *cdb, BYTE *buf); // MODE SENSE command
virtual int FASTCALL ModeSense10(const DWORD *cdb, BYTE *buf); // MODE SENSE(10) command
int FASTCALL ReadDefectData10(const DWORD *cdb, BYTE *buf); // READ DEFECT DATA(10) command
virtual BOOL FASTCALL TestUnitReady(const DWORD *cdb); // TEST UNIT READY command
BOOL FASTCALL Rezero(const DWORD *cdb); // REZERO command
BOOL FASTCALL Format(const DWORD *cdb); // FORMAT UNIT command
BOOL FASTCALL Reassign(const DWORD *cdb); // REASSIGN UNIT command
virtual int FASTCALL Read(BYTE *buf, DWORD block); // READ command
int FASTCALL WriteCheck(DWORD block); // WRITE check
BOOL FASTCALL Write(const BYTE *buf, DWORD block); // WRITE command
BOOL FASTCALL Seek(const DWORD *cdb); // SEEK command
BOOL FASTCALL Assign(const DWORD *cdb); // ASSIGN command
BOOL FASTCALL Specify(const DWORD *cdb); // SPECIFY command
BOOL FASTCALL StartStop(const DWORD *cdb); // START STOP UNIT command
BOOL FASTCALL SendDiag(const DWORD *cdb); // SEND DIAGNOSTIC command
BOOL FASTCALL Removal(const DWORD *cdb); // PREVENT/ALLOW MEDIUM REMOVAL command
int FASTCALL ReadCapacity(const DWORD *cdb, BYTE *buf); // READ CAPACITY command
BOOL FASTCALL Verify(const DWORD *cdb); // VERIFY command
virtual int FASTCALL ReadToc(const DWORD *cdb, BYTE *buf); // READ TOC command
virtual BOOL FASTCALL PlayAudio(const DWORD *cdb); // PLAY AUDIO command
virtual BOOL FASTCALL PlayAudioMSF(const DWORD *cdb); // PLAY AUDIO MSF command
virtual BOOL FASTCALL PlayAudioTrack(const DWORD *cdb); // PLAY AUDIO TRACK command
void FASTCALL InvalidCmd() { disk.code = DISK_INVALIDCMD; } // Unsupported command
// Other
BOOL IsCacheWB() { return cache_wb; }
// Get cache writeback mode
void SetCacheWB(BOOL enable) { cache_wb = enable; }
// Set cache writeback mode
BOOL IsCacheWB() { return cache_wb; } // Get cache writeback mode
void SetCacheWB(BOOL enable) { cache_wb = enable; } // Set cache writeback mode
protected:
// Internal processing
virtual int FASTCALL AddError(BOOL change, BYTE *buf);
// Add error
virtual int FASTCALL AddFormat(BOOL change, BYTE *buf);
// Add format
virtual int FASTCALL AddDrive(BOOL change, BYTE *buf);
// Add drive
int FASTCALL AddOpt(BOOL change, BYTE *buf);
// Add optical
int FASTCALL AddCache(BOOL change, BYTE *buf);
// Add cache
int FASTCALL AddCDROM(BOOL change, BYTE *buf);
// Add CD-ROM
int FASTCALL AddCDDA(BOOL change, BYTE *buf);
// Add CD_DA
virtual int FASTCALL AddVendor(int page, BOOL change, BYTE *buf);
// Add vendor special info
BOOL FASTCALL CheckReady();
// Check if ready
virtual int FASTCALL AddError(BOOL change, BYTE *buf); // Add error
virtual int FASTCALL AddFormat(BOOL change, BYTE *buf); // Add format
virtual int FASTCALL AddDrive(BOOL change, BYTE *buf); // Add drive
int FASTCALL AddOpt(BOOL change, BYTE *buf); // Add optical
int FASTCALL AddCache(BOOL change, BYTE *buf); // Add cache
int FASTCALL AddCDROM(BOOL change, BYTE *buf); // Add CD-ROM
int FASTCALL AddCDDA(BOOL change, BYTE *buf); // Add CD_DA
virtual int FASTCALL AddVendor(int page, BOOL change, BYTE *buf); // Add vendor special info
BOOL FASTCALL CheckReady(); // Check if ready
// Internal data
disk_t disk;
// Internal disk data
Filepath diskpath;
// File path (for GetPath)
BOOL cache_wb;
// Cache mode
disk_t disk; // Internal disk data
Filepath diskpath; // File path (for GetPath)
BOOL cache_wb; // Cache mode
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SASI hard disk ]
// [ SASI hard disk ]
//
//---------------------------------------------------------------------------
#include "sasihd.h"
@ -73,7 +73,7 @@ BOOL FASTCALL SASIHD::Open(const Filepath& path, BOOL /*attn*/)
size = fio.GetFileSize();
fio.Close();
#if defined(USE_MZ1F23_1024_SUPPORT)
#if defined(USE_MZ1F23_1024_SUPPORT)
// MZ-2500/MZ-2800用 MZ-1F23(SASI 20M/セクタサイズ1024)専用
// 20M(22437888 BS=1024 C=21912)
if (size == 0x1566000) {
@ -84,9 +84,9 @@ BOOL FASTCALL SASIHD::Open(const Filepath& path, BOOL /*attn*/)
// Call the base class
return Disk::Open(path);
}
#endif // USE_MZ1F23_1024_SUPPORT
#endif // USE_MZ1F23_1024_SUPPORT
#if defined(REMOVE_FIXED_SASIHD_SIZE)
#if defined(REMOVE_FIXED_SASIHD_SIZE)
// 256バイト単位であること
if (size & 0xff) {
return FALSE;
@ -101,7 +101,7 @@ BOOL FASTCALL SASIHD::Open(const Filepath& path, BOOL /*attn*/)
if (size > 512 * 1024 * 1024) {
return FALSE;
}
#else
#else
// 10MB, 20MB, 40MBのみ
switch (size) {
// 10MB(10441728 BS=256 C=40788)
@ -120,7 +120,7 @@ BOOL FASTCALL SASIHD::Open(const Filepath& path, BOOL /*attn*/)
default:
return FALSE;
}
#endif // REMOVE_FIXED_SASIHD_SIZE
#endif // REMOVE_FIXED_SASIHD_SIZE
// セクタサイズとブロック数
disk.size = 8;

View File

@ -5,10 +5,10 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SASI hard disk ]
//
@ -28,13 +28,10 @@ class SASIHD : public Disk
{
public:
// Basic Functions
SASIHD();
// Constructor
void FASTCALL Reset();
// Reset
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE);
// Open
SASIHD(); // Constructor
void FASTCALL Reset(); // Reset
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
// commands
int FASTCALL RequestSense(const DWORD *cdb, BYTE *buf);
// REQUEST SENSE command
int FASTCALL RequestSense(const DWORD *cdb, BYTE *buf); // REQUEST SENSE command
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Host Bridge for the Sharp X68000 ]
// [ SCSI Host Bridge for the Sharp X68000 ]
//
// Note: This requires a special driver on the host system and will only
// work with the Sharp X68000 operating system.
@ -37,7 +37,7 @@ SCSIBR::SCSIBR() : Disk()
// Host Bridge
disk.id = MAKEID('S', 'C', 'B', 'R');
#if defined(RASCSI) && defined(__linux__) && !defined(BAREMETAL)
#if defined(RASCSI) && defined(__linux__) && !defined(BAREMETAL)
// TAP Driver Generation
tap = new CTapDriver();
m_bTapEnable = tap->Init();
@ -51,7 +51,7 @@ SCSIBR::SCSIBR() : Disk()
// Packet reception flag OFF
packet_enable = FALSE;
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
// Create host file system
fs = new CFileSys();
@ -65,13 +65,13 @@ SCSIBR::SCSIBR() : Disk()
//---------------------------------------------------------------------------
SCSIBR::~SCSIBR()
{
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
// TAP driver release
if (tap) {
tap->Cleanup();
delete tap;
}
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
// Release host file system
if (fs) {
@ -136,12 +136,12 @@ int FASTCALL SCSIBR::Inquiry(
// Optional function valid flag
buf[36] = '0';
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
// TAP Enable
if (m_bTapEnable) {
buf[37] = '1';
}
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
// CFileSys Enable
buf[38] = '1';
@ -182,27 +182,27 @@ int FASTCALL SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
{
int type;
int phase;
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
int func;
int total_len;
int i;
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
ASSERT(this);
// Type
type = cdb[2];
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
// Function number
func = cdb[3];
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
// Phase
phase = cdb[9];
switch (type) {
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
@ -251,7 +251,7 @@ int FASTCALL SCSIBR::GetMessage10(const DWORD *cdb, BYTE *buf)
return total_len;
}
break;
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
case 2: // Host Drive
switch (phase) {
@ -305,7 +305,7 @@ BOOL FASTCALL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
len |= cdb[8];
switch (type) {
#if defined(RASCSI) && !defined(BAREMETAL)
#if defined(RASCSI) && !defined(BAREMETAL)
case 1: // Ethernet
// Do not process if TAP is invalid
if (!m_bTapEnable) {
@ -322,7 +322,7 @@ BOOL FASTCALL SCSIBR::SendMessage10(const DWORD *cdb, BYTE *buf)
return TRUE;
}
break;
#endif // RASCSI && !BAREMETAL
#endif // RASCSI && !BAREMETAL
case 2: // Host drive
switch (phase) {
@ -1462,30 +1462,30 @@ void FASTCALL SCSIBR::WriteFs(int func, BYTE *buf)
func &= 0x1f;
switch (func) {
case 0x00: return FS_InitDevice(buf); // $40 - start device
case 0x01: return FS_CheckDir(buf); // $41 - directory check
case 0x02: return FS_MakeDir(buf); // $42 - create directory
case 0x01: return FS_CheckDir(buf); // $41 - directory check
case 0x02: return FS_MakeDir(buf); // $42 - create directory
case 0x03: return FS_RemoveDir(buf); // $43 - remove directory
case 0x04: return FS_Rename(buf); // $44 - change file name
case 0x05: return FS_Delete(buf); // $45 - delete file
case 0x04: return FS_Rename(buf); // $44 - change file name
case 0x05: return FS_Delete(buf); // $45 - delete file
case 0x06: return FS_Attribute(buf); // $46 - Get/set file attribute
case 0x07: return FS_Files(buf); // $47 - file search
case 0x08: return FS_NFiles(buf); // $48 - next file search
case 0x09: return FS_Create(buf); // $49 - create file
case 0x0A: return FS_Open(buf); // $4A - File open
case 0x0B: return FS_Close(buf); // $4B - File close
case 0x0C: return FS_Read(buf); // $4C - read file
case 0x0D: return FS_Write(buf); // $4D - write file
case 0x0E: return FS_Seek(buf); // $4E - File seek
case 0x07: return FS_Files(buf); // $47 - file search
case 0x08: return FS_NFiles(buf); // $48 - next file search
case 0x09: return FS_Create(buf); // $49 - create file
case 0x0A: return FS_Open(buf); // $4A - File open
case 0x0B: return FS_Close(buf); // $4B - File close
case 0x0C: return FS_Read(buf); // $4C - read file
case 0x0D: return FS_Write(buf); // $4D - write file
case 0x0E: return FS_Seek(buf); // $4E - File seek
case 0x0F: return FS_TimeStamp(buf); // $4F - Get/set file modification time
case 0x10: return FS_GetCapacity(buf); // $50 - get capacity
case 0x11: return FS_CtrlDrive(buf); // $51 - Drive control/state check
case 0x12: return FS_GetDPB(buf); // $52 - Get DPB
case 0x13: return FS_DiskRead(buf); // $53 - read sector
case 0x12: return FS_GetDPB(buf); // $52 - Get DPB
case 0x13: return FS_DiskRead(buf); // $53 - read sector
case 0x14: return FS_DiskWrite(buf); // $54 - write sector
case 0x15: return FS_Ioctrl(buf); // $55 - IOCTRL
case 0x16: return FS_Flush(buf); // $56 - flush
case 0x15: return FS_Ioctrl(buf); // $55 - IOCTRL
case 0x16: return FS_Flush(buf); // $56 - flush
case 0x17: return FS_CheckMedia(buf); // $57 - check media exchange
case 0x18: return FS_Lock(buf); // $58 - exclusive control
case 0x18: return FS_Lock(buf); // $58 - exclusive control
}
}

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Host Bridge for the Sharp X68000 ]
// [ SCSI Host Bridge for the Sharp X68000 ]
//
// Note: This requires a special driver on the host system and will only
// work with the Sharp X68000 operating system.
@ -34,120 +34,68 @@ class SCSIBR : public Disk
{
public:
// Basic Functions
SCSIBR();
// Constructor
virtual ~SCSIBR();
// Destructor
SCSIBR(); // Constructor
virtual ~SCSIBR(); // Destructor
// commands
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);
// INQUIRY command
BOOL FASTCALL TestUnitReady(const DWORD *cdb);
// TEST UNIT READY command
int FASTCALL GetMessage10(const DWORD *cdb, BYTE *buf);
// GET MESSAGE10 command
BOOL FASTCALL SendMessage10(const DWORD *cdb, BYTE *buf);
// SEND MESSAGE10 command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
BOOL FASTCALL TestUnitReady(const DWORD *cdb); // TEST UNIT READY command
int FASTCALL GetMessage10(const DWORD *cdb, BYTE *buf); // GET MESSAGE10 command
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
void FASTCALL GetPacketBuf(BYTE *buf);
// Get a packet
void FASTCALL SendPacket(BYTE *buf, int len);
// Send a packet
#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
void FASTCALL GetPacketBuf(BYTE *buf); // Get a packet
void FASTCALL SendPacket(BYTE *buf, int len); // Send a packet
CTapDriver *tap;
// TAP driver
BOOL m_bTapEnable;
// TAP valid flag
BYTE mac_addr[6];
// MAC Addres
int packet_len;
// Receive packet size
BYTE packet_buf[0x1000];
// Receive packet buffer
BOOL packet_enable;
// Received packet valid
#endif // RASCSI && !BAREMETAL
CTapDriver *tap; // TAP driver
BOOL m_bTapEnable; // TAP valid flag
BYTE mac_addr[6]; // MAC Addres
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)
int FASTCALL ReadFsOpt(BYTE *buf); // Read file system (optional data)
void FASTCALL WriteFs(int func, BYTE *buf); // File system write (execute)
void FASTCALL WriteFsOpt(BYTE *buf, int len); // File system write (optional data)
int FASTCALL ReadFsResult(BYTE *buf);
// Read filesystem (result code)
int FASTCALL ReadFsOut(BYTE *buf);
// Read filesystem (return data)
int FASTCALL ReadFsOpt(BYTE *buf);
// Read file system (optional data)
void FASTCALL WriteFs(int func, BYTE *buf);
// File system write (execute)
void FASTCALL WriteFsOpt(BYTE *buf, int len);
// File system write (optional data)
// Command handlers
void FASTCALL FS_InitDevice(BYTE *buf);
// $40 - boot
void FASTCALL FS_CheckDir(BYTE *buf);
// $41 - directory check
void FASTCALL FS_MakeDir(BYTE *buf);
// $42 - create directory
void FASTCALL FS_RemoveDir(BYTE *buf);
// $43 - delete directory
void FASTCALL FS_Rename(BYTE *buf);
// $44 - change filename
void FASTCALL FS_Delete(BYTE *buf);
// $45 - delete file
void FASTCALL FS_Attribute(BYTE *buf);
// $46 - get/set file attributes
void FASTCALL FS_Files(BYTE *buf);
// $47 - file search
void FASTCALL FS_NFiles(BYTE *buf);
// $48 - find next file
void FASTCALL FS_Create(BYTE *buf);
// $49 - create file
void FASTCALL FS_Open(BYTE *buf);
// $4A - open file
void FASTCALL FS_Close(BYTE *buf);
// $4B - close file
void FASTCALL FS_Read(BYTE *buf);
// $4C - read file
void FASTCALL FS_Write(BYTE *buf);
// $4D - write file
void FASTCALL FS_Seek(BYTE *buf);
// $4E - seek file
void FASTCALL FS_TimeStamp(BYTE *buf);
// $4F - get/set file time
void FASTCALL FS_GetCapacity(BYTE *buf);
// $50 - get capacity
void FASTCALL FS_CtrlDrive(BYTE *buf);
// $51 - drive status check/control
void FASTCALL FS_GetDPB(BYTE *buf);
// $52 - get DPB
void FASTCALL FS_DiskRead(BYTE *buf);
// $53 - read sector
void FASTCALL FS_DiskWrite(BYTE *buf);
// $54 - write sector
void FASTCALL FS_Ioctrl(BYTE *buf);
// $55 - IOCTRL
void FASTCALL FS_Flush(BYTE *buf);
// $56 - flush cache
void FASTCALL FS_CheckMedia(BYTE *buf);
// $57 - check media
void FASTCALL FS_Lock(BYTE *buf);
// $58 - get exclusive control
void FASTCALL FS_InitDevice(BYTE *buf); // $40 - boot
void FASTCALL FS_CheckDir(BYTE *buf); // $41 - directory check
void FASTCALL FS_MakeDir(BYTE *buf); // $42 - create directory
void FASTCALL FS_RemoveDir(BYTE *buf); // $43 - delete directory
void FASTCALL FS_Rename(BYTE *buf); // $44 - change filename
void FASTCALL FS_Delete(BYTE *buf); // $45 - delete file
void FASTCALL FS_Attribute(BYTE *buf); // $46 - get/set file attributes
void FASTCALL FS_Files(BYTE *buf); // $47 - file search
void FASTCALL FS_NFiles(BYTE *buf); // $48 - find next file
void FASTCALL FS_Create(BYTE *buf); // $49 - create file
void FASTCALL FS_Open(BYTE *buf); // $4A - open file
void FASTCALL FS_Close(BYTE *buf); // $4B - close file
void FASTCALL FS_Read(BYTE *buf); // $4C - read file
void FASTCALL FS_Write(BYTE *buf); // $4D - write file
void FASTCALL FS_Seek(BYTE *buf); // $4E - seek file
void FASTCALL FS_TimeStamp(BYTE *buf); // $4F - get/set file time
void FASTCALL FS_GetCapacity(BYTE *buf); // $50 - get capacity
void FASTCALL FS_CtrlDrive(BYTE *buf); // $51 - drive status check/control
void FASTCALL FS_GetDPB(BYTE *buf); // $52 - get DPB
void FASTCALL FS_DiskRead(BYTE *buf); // $53 - read sector
void FASTCALL FS_DiskWrite(BYTE *buf); // $54 - write sector
void FASTCALL FS_Ioctrl(BYTE *buf); // $55 - IOCTRL
void FASTCALL FS_Flush(BYTE *buf); // $56 - flush cache
void FASTCALL FS_CheckMedia(BYTE *buf); // $57 - check media
void FASTCALL FS_Lock(BYTE *buf); // $58 - get exclusive control
CFileSys *fs;
// File system accessor
DWORD fsresult;
// File system access result code
BYTE fsout[0x800];
// File system access result buffer
DWORD fsoutlen;
// File system access result buffer size
BYTE fsopt[0x1000000];
// File system access buffer
DWORD fsoptlen;
// File system access buffer size
CFileSys *fs; // File system accessor
DWORD fsresult; // File system access result code
BYTE fsout[0x800]; // File system access result buffer
DWORD fsoutlen; // File system access result buffer size
BYTE fsopt[0x1000000]; // File system access buffer
DWORD fsoptlen; // File system access buffer size
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Hard Disk for Apple Macintosh ]
// [ SCSI Hard Disk for Apple Macintosh ]
//
//---------------------------------------------------------------------------

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Hard Disk for Apple Macintosh ]
// [ SCSI Hard Disk for Apple Macintosh ]
//
//---------------------------------------------------------------------------
#pragma once
@ -36,50 +36,30 @@ class CDTrack
{
public:
// Basic Functions
CDTrack(SCSICD *scsicd);
// Constructor
virtual ~CDTrack();
// Destructor
BOOL FASTCALL Init(int track, DWORD first, DWORD last);
// Initialization
CDTrack(SCSICD *scsicd); // Constructor
virtual ~CDTrack(); // Destructor
BOOL FASTCALL Init(int track, DWORD first, DWORD last); // Initialization
// Properties
void FASTCALL SetPath(BOOL cdda, const Filepath& path);
// Set the path
void FASTCALL GetPath(Filepath& path) const;
// Get the path
void FASTCALL AddIndex(int index, DWORD lba);
// Add index
DWORD FASTCALL GetFirst() const;
// Get the start LBA
DWORD FASTCALL GetLast() const;
// Get the last LBA
DWORD FASTCALL GetBlocks() const;
// Get the number of blocks
int FASTCALL GetTrackNo() const;
// Get the track number
BOOL FASTCALL IsValid(DWORD lba) const;
// Is this a valid LBA?
BOOL FASTCALL IsAudio() const;
// Is this an audio track?
void FASTCALL SetPath(BOOL cdda, const Filepath& path); // Set the path
void FASTCALL GetPath(Filepath& path) const; // Get the path
void FASTCALL AddIndex(int index, DWORD lba); // Add index
DWORD FASTCALL GetFirst() const; // Get the start LBA
DWORD FASTCALL GetLast() const; // Get the last LBA
DWORD FASTCALL GetBlocks() const; // Get the number of blocks
int FASTCALL GetTrackNo() const; // Get the track number
BOOL FASTCALL IsValid(DWORD lba) const; // Is this a valid LBA?
BOOL FASTCALL IsAudio() const; // Is this an audio track?
private:
SCSICD *cdrom;
// Parent device
BOOL valid;
// Valid track
int track_no;
// Track number
DWORD first_lba;
// First LBA
DWORD last_lba;
// Last LBA
BOOL audio;
// Audio track flag
BOOL raw;
// RAW data flag
Filepath imgpath;
// Image file path
SCSICD *cdrom; // Parent device
BOOL valid; // Valid track
int track_no; // Track number
DWORD first_lba; // First LBA
DWORD last_lba; // Last LBA
BOOL audio; // Audio track flag
BOOL raw; // RAW data flag
Filepath imgpath; // Image file path
};
//===========================================================================
@ -91,47 +71,29 @@ class CDDABuf
{
public:
// Basic Functions
CDDABuf();
// Constructor
virtual ~CDDABuf();
// Destructor
#if 0
BOOL Init();
// Initialization
BOOL FASTCALL Load(const Filepath& path);
// Load
BOOL FASTCALL Save(const Filepath& path);
// Save
CDDABuf(); // Constructor
virtual ~CDDABuf(); // Destructor
#if 0
BOOL Init(); // Initialization
BOOL FASTCALL Load(const Filepath& path); // Load
BOOL FASTCALL Save(const Filepath& path); // Save
// API
void FASTCALL Clear();
// Clear the buffer
BOOL FASTCALL Open(Filepath& path);
// File specification
BOOL FASTCALL GetBuf(DWORD *buffer, int frames);
// Get the buffer
BOOL FASTCALL IsValid();
// Check if Valid
BOOL FASTCALL ReadReq();
// Read Request
BOOL FASTCALL IsEnd() const;
// Finish check
void FASTCALL Clear(); // Clear the buffer
BOOL FASTCALL Open(Filepath& path); // File specification
BOOL FASTCALL GetBuf(DWORD *buffer, int frames); // Get the buffer
BOOL FASTCALL IsValid(); // Check if Valid
BOOL FASTCALL ReadReq(); // Read Request
BOOL FASTCALL IsEnd() const; // Finish check
private:
Filepath wavepath;
// Wave path
BOOL valid;
// Open result (is it valid?)
DWORD *buf;
// Data buffer
DWORD read;
// Read pointer
DWORD write;
// Write pointer
DWORD num;
// Valid number of data
DWORD rest;
// Remaining file size
Filepath wavepath; // Wave path
BOOL valid; // Open result (is it valid?)
DWORD *buf; // Data buffer
DWORD read; // Read pointer
DWORD write; // Write pointer
DWORD num; // Valid number of data
DWORD rest; // Remaining file size
#endif
};
@ -145,86 +107,56 @@ class SCSICD : public Disk
public:
// Number of tracks
enum {
TrackMax = 96 // Maximum number of tracks
TrackMax = 96 // Maximum number of tracks
};
public:
// Basic Functions
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
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
int FASTCALL Read(BYTE *buf, DWORD block);
// READ command
int FASTCALL ReadToc(const DWORD *cdb, BYTE *buf);
// READ TOC command
BOOL FASTCALL PlayAudio(const DWORD *cdb);
// PLAY AUDIO command
BOOL FASTCALL PlayAudioMSF(const DWORD *cdb);
// PLAY AUDIO MSF command
BOOL FASTCALL PlayAudioTrack(const DWORD *cdb);
// PLAY AUDIO TRACK command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
int FASTCALL Read(BYTE *buf, DWORD block); // READ command
int FASTCALL ReadToc(const DWORD *cdb, BYTE *buf); // READ TOC command
BOOL FASTCALL PlayAudio(const DWORD *cdb); // PLAY AUDIO command
BOOL FASTCALL PlayAudioMSF(const DWORD *cdb); // PLAY AUDIO MSF command
BOOL FASTCALL PlayAudioTrack(const DWORD *cdb); // PLAY AUDIO TRACK command
// CD-DA
BOOL FASTCALL NextFrame();
// Frame notification
void FASTCALL GetBuf(DWORD *buffer, int samples, DWORD rate);
// Get CD-DA buffer
BOOL FASTCALL NextFrame(); // Frame notification
void FASTCALL GetBuf(DWORD *buffer, int samples, DWORD rate); // Get CD-DA buffer
// LBA-MSF変換
void FASTCALL LBAtoMSF(DWORD lba, BYTE *msf) const;
// LBA→MSF conversion
DWORD FASTCALL MSFtoLBA(const BYTE *msf) const;
// MSF→LBA conversion
void FASTCALL LBAtoMSF(DWORD lba, BYTE *msf) const; // LBA→MSF conversion
DWORD FASTCALL MSFtoLBA(const BYTE *msf) const; // MSF→LBA conversion
private:
// Open
BOOL FASTCALL OpenCue(const Filepath& path);
// Open(CUE)
BOOL FASTCALL OpenIso(const Filepath& path);
// Open(ISO)
BOOL FASTCALL OpenPhysical(const Filepath& path);
// Open(Physical)
BOOL rawfile;
// RAW flag
BOOL FASTCALL OpenCue(const Filepath& path); // Open(CUE)
BOOL FASTCALL OpenIso(const Filepath& path); // Open(ISO)
BOOL FASTCALL OpenPhysical(const Filepath& path); // Open(Physical)
BOOL rawfile; // RAW flag
// Track management
void FASTCALL ClearTrack();
// Clear the track
int FASTCALL SearchTrack(DWORD lba) const;
// Track search
CDTrack* track[TrackMax];
// Track opbject references
int tracks;
// Effective number of track objects
int dataindex;
// Current data track
int audioindex;
// Current audio track
void FASTCALL ClearTrack(); // Clear the track
int FASTCALL SearchTrack(DWORD lba) const; // Track search
CDTrack* track[TrackMax]; // Track opbject references
int tracks; // Effective number of track objects
int dataindex; // Current data track
int audioindex; // Current audio track
int frame;
// Frame number
int frame; // Frame number
#if 0
CDDABuf da_buf;
// CD-DA buffer
int da_num;
// Number of CD-DA tracks
int da_cur;
// CD-DA current track
int da_next;
// CD-DA next track
BOOL da_req;
// CD-DA data request
#endif
#if 0
CDDABuf da_buf; // CD-DA buffer
int da_num; // Number of CD-DA tracks
int da_cur; // CD-DA current track
int da_next; // CD-DA next track
BOOL da_req; // CD-DA data request
#endif
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI hard disk ]
// [ SCSI hard disk ]
//
//---------------------------------------------------------------------------
#include "scsihd.h"

View File

@ -5,10 +5,10 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI hard disk ]
//
@ -28,17 +28,11 @@ class SCSIHD : public Disk
{
public:
// Basic Functions
SCSIHD();
// Constructor
void FASTCALL Reset();
// Reset
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE);
// Open
SCSIHD(); // Constructor
void FASTCALL Reset(); // Reset
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
// commands
int FASTCALL Inquiry(
const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);
// INQUIRY command
BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length);
// MODE SELECT(6) command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length); // MODE SELECT(6) command
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Hard Disk for Apple Macintosh ]
// [ SCSI Hard Disk for Apple Macintosh ]
//
//---------------------------------------------------------------------------

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Hard Disk for Apple Macintosh ]
// [ SCSI Hard Disk for Apple Macintosh ]
//
//---------------------------------------------------------------------------
#pragma once
@ -26,14 +26,10 @@ class SCSIHD_APPLE : public SCSIHD
{
public:
// Basic Functions
SCSIHD_APPLE();
// Constructor
SCSIHD_APPLE(); // Constructor
// commands
int FASTCALL Inquiry(
const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);
// INQUIRY command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
// Internal processing
int FASTCALL AddVendor(int page, BOOL change, BYTE *buf);
// Add vendor special page
int FASTCALL AddVendor(int page, BOOL change, BYTE *buf); // Add vendor special page
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI NEC "Genuine" Hard Disk]
// [ SCSI NEC "Genuine" Hard Disk]
//
//---------------------------------------------------------------------------

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI NEC "Genuine" Hard Disk]
// [ SCSI NEC "Genuine" Hard Disk]
//
//---------------------------------------------------------------------------
#pragma once
@ -26,36 +26,22 @@ class SCSIHD_NEC : public SCSIHD
{
public:
// Basic Functions
SCSIHD_NEC();
// Constructor
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE);
// Open
SCSIHD_NEC(); // Constructor
BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); // Open
// commands
int FASTCALL Inquiry(
const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor);
// INQUIRY command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
// Internal processing
int FASTCALL AddError(BOOL change, BYTE *buf);
// Add error
int FASTCALL AddFormat(BOOL change, BYTE *buf);
// Add format
int FASTCALL AddDrive(BOOL change, BYTE *buf);
// Add drive
int FASTCALL AddError(BOOL change, BYTE *buf); // Add error
int FASTCALL AddFormat(BOOL change, BYTE *buf); // Add format
int FASTCALL AddDrive(BOOL change, BYTE *buf); // Add drive
private:
int cylinders;
// Number of cylinders
int heads;
// Number of heads
int sectors;
// Number of sectors
int sectorsize;
// Sector size
off64_t imgoffset;
// Image offset
off64_t imgsize;
// Image size
int cylinders; // Number of cylinders
int heads; // Number of heads
int sectors; // Number of sectors
int sectorsize; // Sector size
off64_t imgoffset; // Image offset
off64_t imgsize; // Image size
};

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Magneto-Optical Disk]
// [ SCSI Magneto-Optical Disk]
//
//---------------------------------------------------------------------------

View File

@ -5,12 +5,12 @@
//
// Copyright (C) 2001-2006 (ytanaka@ipc-tokai.or.jp)
// Copyright (C) 2014-2020 GIMONS
// Copyright (C) akuker
// Copyright (C) akuker
//
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
// Licensed under the BSD 3-Clause License.
// See LICENSE file in the project root folder.
//
// [ SCSI Magneto-Optical Disk]
// [ SCSI Magneto-Optical Disk]
//
//---------------------------------------------------------------------------
#pragma once
@ -28,22 +28,16 @@ class SCSIMO : public Disk
{
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
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
BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length);
// MODE SELECT(6) command
int FASTCALL Inquiry(const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); // INQUIRY command
BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length); // MODE SELECT(6) command
// Internal processing
int FASTCALL AddVendor(int page, BOOL change, BYTE *buf);
// Add vendor special page
int FASTCALL AddVendor(int page, BOOL change, BYTE *buf); // Add vendor special page
};

View File

@ -7,39 +7,39 @@ from settings import *
def make_cd(file_path, file_type, file_creator):
with open(file_path, "rb") as f:
file_bytes = f.read()
file_name = file_path.split('/')[-1]
file_suffix = file_name.split('.')[-1]
file_name = file_path.split("/")[-1]
file_suffix = file_name.split(".")[-1]
if file_type is None and file_creator is None:
if file_suffix.lower() == 'sea':
file_type = '.sea'
file_creator = 'APPL'
if file_suffix.lower() == "sea":
file_type = ".sea"
file_creator = "APPL"
v = Volume()
v.name = "TestName"
v['Folder'] = Folder()
v["Folder"] = Folder()
v['Folder'][file_name] = File()
v['Folder'][file_name].data = file_bytes
v['Folder'][file_name].rsrc = b''
v["Folder"][file_name] = File()
v["Folder"][file_name].data = file_bytes
v["Folder"][file_name].rsrc = b""
if not (file_type is None and file_creator is None):
v['Folder'][file_name].type = bytearray(file_type)
v['Folder'][file_name].creator = bytearray(file_creator)
v["Folder"][file_name].type = bytearray(file_type)
v["Folder"][file_name].creator = bytearray(file_creator)
padding = (len(file_bytes) % 512) + (512 * 50)
print("mod", str(len(file_bytes) % 512))
print("padding " + str(padding))
print("len " + str(len(file_bytes)))
print("total " + str(len(file_bytes) + padding))
with open(base_dir + 'test.hda', 'wb') as f:
with open(base_dir + "test.hda", "wb") as f:
flat = v.write(
size=len(file_bytes) + padding,
align=512, # Allocation block alignment modulus (2048 for CDs)
desktopdb=True, # Create a dummy Desktop Database to prevent a rebuild on boot
bootable=False, # This requires a folder with a ZSYS and a FNDR file
startapp=('Folder', file_name), # Path (as tuple) to an app to open at boot
startapp=("Folder", file_name), # Path (as tuple) to an app to open at boot
)
f.write(flat)
return base_dir + 'test.hda'
return base_dir + "test.hda"

View File

@ -5,8 +5,9 @@ import time
from ractl_cmds import attach_image
from settings import *
valid_file_types = ['*.hda', '*.iso', '*.cdr']
valid_file_types = r'|'.join([fnmatch.translate(x) for x in valid_file_types])
valid_file_types = ["*.hda", "*.iso", "*.cdr"]
valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_types])
def create_new_image(file_name, type, size):
@ -15,8 +16,10 @@ def create_new_image(file_name, type, size):
else:
file_name = file_name + "." + type
return subprocess.run(["dd", "if=/dev/zero", "of=" + base_dir + file_name, "bs=1M", "count=" + size],
capture_output=True)
return subprocess.run(
["dd", "if=/dev/zero", "of=" + base_dir + file_name, "bs=1M", "count=" + size],
capture_output=True,
)
def delete_image(file_name):
@ -30,18 +33,24 @@ def delete_image(file_name):
def unzip_file(file_name):
import zipfile
with zipfile.ZipFile(base_dir + file_name, 'r') as zip_ref:
with zipfile.ZipFile(base_dir + file_name, "r") as zip_ref:
zip_ref.extractall(base_dir)
return True
def rascsi_service(action):
# start/stop/restart
return subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode == 0
return (
subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode
== 0
)
def download_file_to_iso(scsi_id, url):
import urllib.request
file_name = url.split('/')[-1]
file_name = url.split("/")[-1]
tmp_ts = int(time.time())
tmp_dir = "/tmp/" + str(tmp_ts) + "/"
os.mkdir(tmp_dir)
@ -50,15 +59,18 @@ def download_file_to_iso(scsi_id, url):
urllib.request.urlretrieve(url, tmp_full_path)
# iso_filename = make_cd(tmp_full_path, None, None) # not working yet
iso_proc = subprocess.run(["genisoimage", "-hfs", "-o", iso_filename, tmp_full_path], capture_output=True)
iso_proc = subprocess.run(
["genisoimage", "-hfs", "-o", iso_filename, tmp_full_path], capture_output=True
)
if iso_proc.returncode != 0:
return iso_proc
return attach_image(scsi_id, iso_filename, "cd")
return attach_image(scsi_id, iso_filename, "SCCD")
def download_image(url):
import urllib.request
file_name = url.split('/')[-1]
file_name = url.split("/")[-1]
full_path = base_dir + file_name
urllib.request.urlretrieve(url, full_path)

12
src/web/mock/bin/brctl Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Mock responses to rascsi-web
case $1 in
"show")
echo "rascsi_bridge 8000.dca632b05dd1 no eth0"
;;
**)
echo "default"
;;
esac

12
src/web/mock/bin/ip Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Mock responses to rascsi-web
case $1 in
"link")
echo "link here"
;;
**)
echo "default"
;;
esac

View File

@ -3,7 +3,10 @@ import subprocess
def rascsi_service(action):
# start/stop/restart
return subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode == 0
return (
subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode
== 0
)
def reboot_pi():
@ -15,6 +18,14 @@ def shutdown_pi():
def running_version():
ra_web_version = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True).stdout.decode("utf-8").strip()
pi_version = subprocess.run(["uname", "-a"], capture_output=True).stdout.decode("utf-8").strip()
ra_web_version = (
subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True)
.stdout.decode("utf-8")
.strip()
)
pi_version = (
subprocess.run(["uname", "-a"], capture_output=True)
.stdout.decode("utf-8")
.strip()
)
return ra_web_version + " " + pi_version

View File

@ -4,8 +4,9 @@ import subprocess
import re
from settings import *
valid_file_types = ['*.hda', '*.iso', '*.cdr', '*.zip']
valid_file_types = r'|'.join([fnmatch.translate(x) for x in valid_file_types])
valid_file_types = ["*.hda", "*.iso", "*.cdr", "*.zip"]
valid_file_types = r"|".join([fnmatch.translate(x) for x in valid_file_types])
# List of SCSI ID's you'd like to exclude - eg if you are on a Mac, the System is usually 7
EXCLUDE_SCSI_IDS = [7]
@ -20,19 +21,36 @@ def list_files():
for path, dirs, files in os.walk(base_dir):
# Only list valid file types
files = [f for f in files if re.match(valid_file_types, f)]
files_list.extend([
(os.path.join(path, file),
# TODO: move formatting to template
'{:,.0f}'.format(os.path.getsize(os.path.join(path, file)) / float(1 << 20)) + " MB")
for file in files])
files_list.extend(
[
(
os.path.join(path, file),
# TODO: move formatting to template
"{:,.0f}".format(
os.path.getsize(os.path.join(path, file)) / float(1 << 20)
)
+ " MB",
)
for file in files
]
)
return files_list
def list_config_files():
files_list = []
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith(".csv"):
files_list.append(file)
return files_list
def get_valid_scsi_ids(devices):
invalid_list = EXCLUDE_SCSI_IDS.copy()
for device in devices:
if device['file'] != "NO MEDIA" and device['file'] != "-":
invalid_list.append(int(device['id']))
if device["file"] != "NO MEDIA" and device["file"] != "-":
invalid_list.append(int(device["id"]))
valid_list = list(range(8))
for id in invalid_list:
@ -46,19 +64,33 @@ def get_type(scsi_id):
return list_devices()[int(scsi_id)]["type"]
def attach_image(scsi_id, image, type):
if type == "cd" and get_type(scsi_id) == "SCCD":
def attach_image(scsi_id, image, device_type):
if device_type == "SCCD" and get_type(scsi_id) == "SCCD":
return insert(scsi_id, image)
elif device_type == "SCDP":
attach_daynaport(scsi_id)
else:
return subprocess.run(["rasctl", "-c", "attach", "-t", type, "-i", scsi_id, "-f", image], capture_output=True)
if device_type == "SCCD":
device_type = "cd"
return subprocess.run(
["rasctl", "-c", "attach", "-t", device_type, "-i", scsi_id, "-f", image],
capture_output=True,
)
def detach_by_id(scsi_id):
return subprocess.run(["rasctl", "-c" "detach", "-i", scsi_id], capture_output=True)
def detach_all():
for scsi_id in range(0, 7):
subprocess.run(["rasctl", "-c" "detach", "-i", str(scsi_id)])
def disconnect_by_id(scsi_id):
return subprocess.run(["rasctl", "-c", "disconnect", "-i", scsi_id], capture_output=True)
return subprocess.run(
["rasctl", "-c", "disconnect", "-i", scsi_id], capture_output=True
)
def eject_by_id(scsi_id):
@ -66,33 +98,67 @@ def eject_by_id(scsi_id):
def insert(scsi_id, image):
return subprocess.run(["rasctl", "-i", scsi_id, "-c", "insert", "-f", image], capture_output=True)
return subprocess.run(
["rasctl", "-i", scsi_id, "-c", "insert", "-f", image], capture_output=True
)
def attach_daynaport(scsi_id):
return subprocess.run(
["rasctl", "-i", scsi_id, "-c", "attach", "-t", "daynaport"],
capture_output=True,
)
def is_bridge_setup(interface):
process = subprocess.run(["brctl", "show"], capture_output=True)
output = process.stdout.decode("utf-8")
if "rascsi_bridge" in output and interface in output:
return True
return False
def daynaport_setup_bridge(interface):
return subprocess.run(
[f"{base_dir}../RASCSI/src/raspberrypi/setup_bridge.sh", interface],
capture_output=True,
)
def rascsi_service(action):
# start/stop/restart
return subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode == 0
return (
subprocess.run(["sudo", "/bin/systemctl", action, "rascsi.service"]).returncode
== 0
)
def list_devices():
device_list = []
for id in range(8):
device_list.append({"id": str(id), "un": "-", "type": "-", "file": "-"})
output = subprocess.run(["rasctl", "-l"], capture_output=True).stdout.decode("utf-8")
output = subprocess.run(["rasctl", "-l"], capture_output=True).stdout.decode(
"utf-8"
)
for line in output.splitlines():
# Valid line to process, continue
if not line.startswith("+") and \
not line.startswith("| ID |") and \
(not line.startswith("No device is installed.") or line.startswith("No images currently attached.")) \
and len(line) > 0:
if (
not line.startswith("+")
and not line.startswith("| ID |")
and (
not line.startswith("No device is installed.")
or line.startswith("No images currently attached.")
)
and len(line) > 0
):
line.rstrip()
device = {}
segments = line.split("|")
if len(segments) > 4:
idx = int(segments[1].strip())
device_list[idx]["id"] = str(idx)
device_list[idx]['un'] = segments[2].strip()
device_list[idx]['type'] = segments[3].strip()
device_list[idx]['file'] = segments[4].strip()
device_list[idx]["un"] = segments[2].strip()
device_list[idx]["type"] = segments[3].strip()
device_list[idx]["file"] = segments[4].strip()
return device_list

View File

@ -1,4 +1,4 @@
import os
base_dir = os.getenv('BASE_DIR', "/home/pi/images/")
MAX_FILE_SIZE = os.getenv('MAX_FILE_SIZE', 1024 * 1024 * 1024 * 2) # 2gb
base_dir = os.getenv("BASE_DIR", "/home/pi/images/")
MAX_FILE_SIZE = os.getenv("MAX_FILE_SIZE", 1024 * 1024 * 1024 * 2) # 2gb

View File

@ -17,10 +17,26 @@
</tr>
</tbody>
</table>
{% endblock %}
{% endblock %}
{% block content %}
<h2>Current RaSCSI Configuration</h2>
<form action="/config/load" method="post">
<select name="name" >
{% for config in config_files %}
<option value="{{config}}">{{config.replace(".csv", '')}}</option>
{% endfor %}
</select>
<input type="submit" value="Load" />
</form>
<form action="/config/save" method="post">
<input name="name" placeholder="default">
<input type="submit" value="Save" />
</form>
<form action="/scsi/detach_all" method="post" onsubmit="return confirm('Detach all SCSI Devices?')">
<input type="submit" value="Detach All" />
</form>
<table cellpadding="3" border="black">
<tbody>
<tr>
@ -103,7 +119,35 @@
</table>
<hr/>
<h2>Attach Ethernet Adapter</h2>
<p>Emulates a SCSI DaynaPORT Ethernet Adapter. Host drivers required.</p>
<table style="border: none">
<tr style="border: none">
<td style="border: none; vertical-align:top;">
<form action="/daynaport/attach" method="post">
<select name="scsi_id">
{% for id in scsi_ids %}
<option value="{{id}}">{{id}}</option>
{% endfor %}
</select>
<input type="submit" value="Attach" />
</form>
</td>
</tr>
<tr style="border: none">
<td style="border: none; vertical-align:top;">
{% if bridge_configured %}
<small>Bridge is currently configured!</small>
{% else %}
<form action="/daynaport/setup" method="post">
<input type="submit" value="Create Bridge" />
</form>
{% endif %}
</td>
</tr>
</table>
<hr/>
<h2>Upload File</h2>
<p>Uploads file to <tt>{{base_dir}}</tt>. Max file size is set to {{max_file_size / 1024 /1024 }}MB</p>
<table style="border: none">
@ -183,7 +227,6 @@
</table>
<hr/>
<h2>Raspberry Pi Operations</h2>
<table style="border: none">
<tr style="border: none">

View File

@ -1,206 +1,298 @@
import os
from flask import Flask, render_template, request, flash, url_for, redirect, send_file
from werkzeug.utils import secure_filename
from file_cmds import create_new_image, download_file_to_iso, delete_image, unzip_file, download_image
from file_cmds import (
create_new_image,
download_file_to_iso,
delete_image,
unzip_file,
download_image,
)
from pi_cmds import shutdown_pi, reboot_pi, running_version, rascsi_service
from ractl_cmds import attach_image, list_devices, is_active, list_files, detach_by_id, eject_by_id, get_valid_scsi_ids
from ractl_cmds import (
attach_image,
list_devices,
is_active,
list_files,
detach_by_id,
eject_by_id,
get_valid_scsi_ids,
attach_daynaport,
is_bridge_setup,
daynaport_setup_bridge,
list_config_files,
detach_all,
)
from settings import *
app = Flask(__name__)
@app.route('/')
@app.route("/")
def index():
devices = list_devices()
scsi_ids = get_valid_scsi_ids(devices)
return render_template('index.html',
devices=devices,
active=is_active(),
files=list_files(),
base_dir=base_dir,
scsi_ids=scsi_ids,
max_file_size=MAX_FILE_SIZE,
version=running_version())
return render_template(
"index.html",
bridge_configured=is_bridge_setup("eth0"),
devices=devices,
active=is_active(),
files=list_files(),
config_files=list_config_files(),
base_dir=base_dir,
scsi_ids=scsi_ids,
max_file_size=MAX_FILE_SIZE,
version=running_version(),
)
@app.route('/logs')
@app.route("/config/save", methods=["POST"])
def config_save():
file_name = request.form.get("name") or "default"
file_name = f"{base_dir}{file_name}.csv"
import csv
with open(file_name, "w") as csv_file:
writer = csv.writer(csv_file)
for device in list_devices():
if device["type"] is not "-":
writer.writerow(device.values())
flash(f"Saved config to {file_name}!")
return redirect(url_for("index"))
@app.route("/config/load", methods=["POST"])
def config_load():
file_name = request.form.get("name") or "default.csv"
file_name = f"{base_dir}{file_name}"
detach_all()
import csv
with open(file_name) as csv_file:
config_reader = csv.reader(csv_file)
for row in config_reader:
image_name = row[3].replace("(WRITEPROTECT)", "")
attach_image(row[0], image_name, row[2])
flash(f"Loaded config from {file_name}!")
return redirect(url_for("index"))
@app.route("/logs")
def logs():
import subprocess
lines = request.args.get('lines') or "100"
lines = request.args.get("lines") or "100"
process = subprocess.run(["journalctl", "-n", lines], capture_output=True)
if process.returncode == 0:
headers = { 'content-type':'text/plain' }
headers = {"content-type": "text/plain"}
return process.stdout.decode("utf-8"), 200, headers
else:
flash(u'Failed to get logs')
flash(process.stdout.decode("utf-8"), 'stdout')
flash(process.stderr.decode("utf-8"), 'stderr')
return redirect(url_for('index'))
flash("Failed to get logs")
flash(process.stdout.decode("utf-8"), "stdout")
flash(process.stderr.decode("utf-8"), "stderr")
return redirect(url_for("index"))
@app.route('/scsi/attach', methods=['POST'])
@app.route("/daynaport/attach", methods=["POST"])
def daynaport_attach():
scsi_id = request.form.get("scsi_id")
process = attach_daynaport(scsi_id)
if process.returncode == 0:
flash(f"Attached DaynaPORT to SCSI id {scsi_id}!")
return redirect(url_for("index"))
else:
flash(f"Failed to attach DaynaPORT to SCSI id {scsi_id}!", "error")
flash(process.stdout.decode("utf-8"), "stdout")
flash(process.stderr.decode("utf-8"), "stderr")
return redirect(url_for("index"))
@app.route("/daynaport/setup", methods=["POST"])
def daynaport_setup():
# Future use for wifi
interface = request.form.get("interface") or "eth0"
process = daynaport_setup_bridge(interface)
if process.returncode == 0:
flash(f"Configured DaynaPORT bridge on {interface}!")
return redirect(url_for("index"))
else:
flash(f"Failed to configure DaynaPORT bridge on {interface}!", "error")
flash(process.stdout.decode("utf-8"), "stdout")
flash(process.stderr.decode("utf-8"), "stderr")
return redirect(url_for("index"))
@app.route("/scsi/attach", methods=["POST"])
def attach():
file_name = request.form.get('file_name')
scsi_id = request.form.get('scsi_id')
file_name = request.form.get("file_name")
scsi_id = request.form.get("scsi_id")
# Validate image type by suffix
if file_name.lower().endswith('.iso') or file_name.lower().endswith('iso'):
if file_name.lower().endswith(".iso") or file_name.lower().endswith("iso"):
image_type = "cd"
elif file_name.lower().endswith('.hda'):
elif file_name.lower().endswith(".hda"):
image_type = "hd"
else:
flash(u'Unknown file type. Valid files are .iso, .hda, .cdr', 'error')
return redirect(url_for('index'))
flash("Unknown file type. Valid files are .iso, .hda, .cdr", "error")
return redirect(url_for("index"))
process = attach_image(scsi_id, file_name, image_type)
if process.returncode == 0:
flash('Attached '+ file_name + " to scsi id " + scsi_id + "!")
return redirect(url_for('index'))
flash(f"Attached {file_name} to SCSI id {scsi_id}!")
return redirect(url_for("index"))
else:
flash(u'Failed to attach '+ file_name + " to scsi id " + scsi_id + "!", 'error')
flash(process.stdout.decode("utf-8"), 'stdout')
flash(process.stderr.decode("utf-8"), 'stderr')
return redirect(url_for('index'))
flash(f"Failed to attach {file_name} to SCSI id {scsi_id}!", "error")
flash(process.stdout.decode("utf-8"), "stdout")
flash(process.stderr.decode("utf-8"), "stderr")
return redirect(url_for("index"))
@app.route('/scsi/detach', methods=['POST'])
@app.route("/scsi/detach_all", methods=["POST"])
def detach_all_devices():
detach_all()
flash("Detached all SCSI devices!")
return redirect(url_for("index"))
@app.route("/scsi/detach", methods=["POST"])
def detach():
scsi_id = request.form.get('scsi_id')
scsi_id = request.form.get("scsi_id")
process = detach_by_id(scsi_id)
if process.returncode == 0:
flash("Detached scsi id " + scsi_id + "!")
return redirect(url_for('index'))
flash("Detached SCSI id " + scsi_id + "!")
return redirect(url_for("index"))
else:
flash(u"Failed to detach scsi id " + scsi_id + "!", 'error')
flash(process.stdout, 'stdout')
flash(process.stderr, 'stderr')
return redirect(url_for('index'))
flash("Failed to detach SCSI id " + scsi_id + "!", "error")
flash(process.stdout, "stdout")
flash(process.stderr, "stderr")
return redirect(url_for("index"))
@app.route('/scsi/eject', methods=['POST'])
@app.route("/scsi/eject", methods=["POST"])
def eject():
scsi_id = request.form.get('scsi_id')
scsi_id = request.form.get("scsi_id")
process = eject_by_id(scsi_id)
if process.returncode == 0:
flash("Ejected scsi id " + scsi_id + "!")
return redirect(url_for('index'))
return redirect(url_for("index"))
else:
flash(u"Failed to eject scsi id " + scsi_id + "!", 'error')
flash(process.stdout, 'stdout')
flash(process.stderr, 'stderr')
return redirect(url_for('index'))
flash("Failed to eject SCSI id " + scsi_id + "!", "error")
flash(process.stdout, "stdout")
flash(process.stderr, "stderr")
return redirect(url_for("index"))
@app.route('/pi/reboot', methods=['POST'])
@app.route("/pi/reboot", methods=["POST"])
def restart():
reboot_pi()
flash("Restarting...")
return redirect(url_for('index'))
return redirect(url_for("index"))
@app.route('/rascsi/restart', methods=['POST'])
@app.route("/rascsi/restart", methods=["POST"])
def rascsi_restart():
rascsi_service("restart")
flash("Restarting RaSCSI Service...")
return redirect(url_for('index'))
return redirect(url_for("index"))
@app.route('/pi/shutdown', methods=['POST'])
@app.route("/pi/shutdown", methods=["POST"])
def shutdown():
shutdown_pi()
flash("Shutting down...")
return redirect(url_for('index'))
return redirect(url_for("index"))
@app.route('/files/download_to_iso', methods=['POST'])
@app.route("/files/download_to_iso", methods=["POST"])
def download_file():
scsi_id = request.form.get('scsi_id')
url = request.form.get('url')
scsi_id = request.form.get("scsi_id")
url = request.form.get("url")
process = download_file_to_iso(scsi_id, url)
if process.returncode == 0:
flash("File Downloaded")
return redirect(url_for('index'))
return redirect(url_for("index"))
else:
flash(u"Failed to download file", 'error')
flash(process.stdout, 'stdout')
flash(process.stderr, 'stderr')
return redirect(url_for('index'))
flash("Failed to download file", "error")
flash(process.stdout, "stdout")
flash(process.stderr, "stderr")
return redirect(url_for("index"))
@app.route('/files/download_image', methods=['POST'])
@app.route("/files/download_image", methods=["POST"])
def download_img():
url = request.form.get('url')
url = request.form.get("url")
# TODO: error handling
download_image(url)
flash("File Downloaded")
return redirect(url_for('index'))
return redirect(url_for("index"))
@app.route('/files/upload', methods=['POST'])
@app.route("/files/upload", methods=["POST"])
def upload_file():
if 'file' not in request.files:
flash('No file part', 'error')
return redirect(url_for('index'))
file = request.files['file']
if "file" not in request.files:
flash("No file part", "error")
return redirect(url_for("index"))
file = request.files["file"]
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('index', filename=filename))
file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
return redirect(url_for("index", filename=filename))
@app.route('/files/create', methods=['POST'])
@app.route("/files/create", methods=["POST"])
def create_file():
file_name = request.form.get('file_name')
size = request.form.get('size')
type = request.form.get('type')
file_name = request.form.get("file_name")
size = request.form.get("size")
type = request.form.get("type")
process = create_new_image(file_name, type, size)
if process.returncode == 0:
flash("Drive created")
return redirect(url_for('index'))
return redirect(url_for("index"))
else:
flash(u"Failed to create file", 'error')
flash(process.stdout, 'stdout')
flash(process.stderr, 'stderr')
return redirect(url_for('index'))
flash("Failed to create file", "error")
flash(process.stdout, "stdout")
flash(process.stderr, "stderr")
return redirect(url_for("index"))
@app.route('/files/download', methods=['POST'])
@app.route("/files/download", methods=["POST"])
def download():
image = request.form.get('image')
image = request.form.get("image")
return send_file(base_dir + image, as_attachment=True)
@app.route('/files/delete', methods=['POST'])
@app.route("/files/delete", methods=["POST"])
def delete():
image = request.form.get('image')
image = request.form.get("image")
if delete_image(image):
flash("File " + image + " deleted")
return redirect(url_for('index'))
return redirect(url_for("index"))
else:
flash(u"Failed to Delete " + image, 'error')
return redirect(url_for('index'))
flash("Failed to Delete " + image, "error")
return redirect(url_for("index"))
@app.route('/files/unzip', methods=['POST'])
@app.route("/files/unzip", methods=["POST"])
def unzip():
image = request.form.get('image')
image = request.form.get("image")
if unzip_file(image):
flash("Unzipped file " + image)
return redirect(url_for('index'))
return redirect(url_for("index"))
else:
flash(u"Failed to unzip " + image, 'error')
return redirect(url_for('index'))
flash("Failed to unzip " + image, "error")
return redirect(url_for("index"))
if __name__ == "__main__":
app.secret_key = 'rascsi_is_awesome_insecure_secret_key'
app.config['SESSION_TYPE'] = 'filesystem'
app.config['UPLOAD_FOLDER'] = base_dir
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
app.config['MAX_CONTENT_LENGTH'] = MAX_FILE_SIZE
app.secret_key = "rascsi_is_awesome_insecure_secret_key"
app.config["SESSION_TYPE"] = "filesystem"
app.config["UPLOAD_FOLDER"] = base_dir
os.makedirs(app.config["UPLOAD_FOLDER"], exist_ok=True)
app.config["MAX_CONTENT_LENGTH"] = MAX_FILE_SIZE
from waitress import serve
serve(app, host="0.0.0.0", port=8080)

View File

@ -15,7 +15,7 @@ The ${service_name} Service Should be Running
The ${service_name} Service Should be Stopped
${lc_service_name}= Convert To Lower Case ${service_name}
${output}= Execute Command systemctl status ${lc_service_name}
Should Contain ${output} Active: failed ignore_case=True
Should Contain Any ${output} Active: failed Active: inactive ignore_case=True
The ${service_name} Service is Stopped
${lc_service_name}= Convert To Lower Case ${service_name}