2016-12-23 17:11:59 +01:00
|
|
|
/* Copyright holders: SA1988, Tenshi
|
2016-11-12 15:06:38 +01:00
|
|
|
see COPYING for more details
|
|
|
|
|
*/
|
|
|
|
|
/*SCSI layer emulation*/
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "86box.h"
|
|
|
|
|
#include "ibm.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
|
|
|
|
|
#include "cdrom.h"
|
|
|
|
|
#include "scsi.h"
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
2016-12-27 22:38:09 +01:00
|
|
|
int SCSICallback[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
2016-11-12 15:06:38 +01:00
|
|
|
uint8_t scsi_cdrom_id = 3; /*common setting*/
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Get the transfer length of the command
|
|
|
|
|
void SCSIGetLength(uint8_t id, int *datalen)
|
2016-11-12 15:06:38 +01:00
|
|
|
{
|
2016-12-23 17:11:59 +01:00
|
|
|
*datalen = SCSIDevices[id].CmdBufferLength;
|
2016-11-12 15:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Execute SCSI command
|
2017-01-03 19:07:18 +01:00
|
|
|
void SCSIExecCommand(uint8_t id, uint8_t *buffer, uint8_t *cdb)
|
2016-11-12 15:06:38 +01:00
|
|
|
{
|
2017-01-03 19:07:18 +01:00
|
|
|
SCSICDROM_Command(id, buffer, cdb);
|
2016-11-12 15:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Read pending data from the resulting SCSI command
|
|
|
|
|
void SCSIReadData(uint8_t id, uint8_t *cdb, uint8_t *data, int datalen)
|
2016-11-12 15:06:38 +01:00
|
|
|
{
|
2016-12-23 17:11:59 +01:00
|
|
|
SCSICDROM_ReadData(id, cdb, data, datalen);
|
|
|
|
|
}
|
2016-11-12 15:06:38 +01:00
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
/////
|
|
|
|
|
void SCSIDMAResetPosition(uint8_t Id)
|
|
|
|
|
{
|
2016-12-27 18:48:38 +01:00
|
|
|
//Reset position in memory after reaching its limit
|
2016-12-23 17:11:59 +01:00
|
|
|
SCSIDevices[Id].pos = 0;
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Read data from buffer with given position in buffer memory
|
2017-01-03 19:07:18 +01:00
|
|
|
void SCSIRead(uint8_t Id, uint8_t *dstbuf, uint8_t *srcbuf, uint32_t len_size)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
2016-12-23 17:11:59 +01:00
|
|
|
if (!len_size) //If there's no data, don't try to do anything.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int c;
|
2016-12-23 03:16:24 +01:00
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
for (c = 0; c <= len_size; c++) //Count as many bytes as the length of the buffer is requested
|
|
|
|
|
{
|
2017-01-03 19:07:18 +01:00
|
|
|
memcpy(dstbuf, srcbuf + SCSIDevices[Id].pos, len_size);
|
2016-12-23 17:11:59 +01:00
|
|
|
SCSIDevices[Id].pos = c;
|
|
|
|
|
|
|
|
|
|
//pclog("SCSI Read: position at %i\n", SCSIDevices[Id].pos);
|
|
|
|
|
}
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Write data to buffer with given position in buffer memory
|
2017-01-03 19:07:18 +01:00
|
|
|
void SCSIWrite(uint8_t Id, uint8_t *srcbuf, uint8_t *dstbuf, uint32_t len_size)
|
2016-11-12 15:06:38 +01:00
|
|
|
{
|
2016-12-23 17:11:59 +01:00
|
|
|
int c;
|
2016-11-12 15:06:38 +01:00
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
for (c = 0; c <= len_size; c++) //Count as many bytes as the length of the buffer is requested
|
|
|
|
|
{
|
2017-01-03 19:07:18 +01:00
|
|
|
memcpy(srcbuf + SCSIDevices[Id].pos, dstbuf, len_size);
|
2016-12-23 17:11:59 +01:00
|
|
|
SCSIDevices[Id].pos = c;
|
|
|
|
|
|
|
|
|
|
//pclog("SCSI Write: position at %i\n", SCSIDevices[Id].pos);
|
|
|
|
|
}
|
2016-11-12 15:06:38 +01:00
|
|
|
}
|
2016-12-23 17:11:59 +01:00
|
|
|
/////
|
2016-11-12 15:06:38 +01:00
|
|
|
|
2016-12-23 17:11:59 +01:00
|
|
|
//Initialization function for the SCSI layer
|
2016-12-30 00:42:54 +01:00
|
|
|
void SCSIReset(uint8_t Id)
|
2016-12-23 17:11:59 +01:00
|
|
|
{
|
2016-11-12 15:06:38 +01:00
|
|
|
page_flags[GPMODE_CDROM_AUDIO_PAGE] &= 0xFD; /* Clear changed flag for CDROM AUDIO mode page. */
|
|
|
|
|
memset(mode_pages_in[GPMODE_CDROM_AUDIO_PAGE], 0, 256); /* Clear the page itself. */
|
2016-12-23 17:11:59 +01:00
|
|
|
|
2016-12-30 00:42:54 +01:00
|
|
|
SCSICallback[Id]=0;
|
|
|
|
|
|
|
|
|
|
if (cdrom_enabled && scsi_cdrom_enabled)
|
2016-11-12 15:06:38 +01:00
|
|
|
{
|
2016-12-30 00:42:54 +01:00
|
|
|
SCSIDevices[Id].LunType = SCSI_CDROM;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SCSIDevices[Id].LunType = SCSI_NONE;
|
2016-12-23 17:11:59 +01:00
|
|
|
}
|
2016-12-27 18:48:38 +01:00
|
|
|
|
2016-11-12 15:06:38 +01:00
|
|
|
page_flags[GPMODE_CDROM_AUDIO_PAGE] &= ~PAGE_CHANGED;
|
2016-12-23 17:11:59 +01:00
|
|
|
|
|
|
|
|
SCSISense.UnitAttention = 0;
|
|
|
|
|
}
|