Module scsi

Module scsi 

Source
Expand description

The drive’s SCSI-class controller: bus signals, phases, the REQ/ACK handshake, the commands (scsi.py).

The CD unit’s controller is not emulated as a microcontroller (there is no second CPU on this machine); it is a bus state machine that the System Card drives through $1800-$1802 and $1808 [hw: pcetech 8; emu: Mesen2 PceScsiBus.cpp, Geargrafx scsi_controller.cpp, Mednafen scsicd.cpp, ares pcd/scsi.cpp, MAME pce_cd.cpp all do the same]. Everything here is time in master clocks (21.477272 MHz); the unit calls run_to(mclk) before register accesses and the bus then runs its own timers up to that instant.

Signals ($1800 read): D3 I/O, D4 C/D, D5 MSG, D6 REQ, D7 BSY. Phases and the signals they hold:

phaseBSYC/DI/OMSGREQwhat the CPU does
bus freewrites $1800 (selects the drive)
command111writes command bytes to $1801
data in11(1)reads bytes from $1801/$1808
status111(1)reads the status byte
message in1111(1)reads the message byte
busy1waits (an audio command in progress)

Every byte is a REQ/ACK handshake: the drive raises REQ, the CPU sets ACK ($1802 bit 7), the drive drops REQ, the CPU drops ACK. IRQ2 sources ($1803 bits): data-in 0x40 and status/message 0x20 are REQ held in those phases (CdUnit turns the levels into IRQ2).

The timings are ScsiSwitches (the reference’s class attributes), all provisional (U8): the only measurements of this hardware are Shadoff’s seek table (tier 3) and the test ROMs Mesen2’s author ran on a real console (tier 5, claimed in his source comments).

Differences forced by Rust:

  • The bus owns the audio player (bus.cdda), where the reference’s bus and unit hold the same object; the player’s on_good_status callback is cdda.good_status_due, answered here right after the player ran (run_cdda).
  • The irq callback into the unit is a list, irq_changes, of (mask, level) in the order the reference would have called; the unit applies it after each call into the bus (nothing the callback reads can change in between).
  • The command list cmd, the buffer out and the ports are bytes; a sector with no disc in the drive (the reference asserts) reads as zeros.

Structs§

ScsiBus
Signals, phase, timers and the command set. irq_changes collects (mask, level) when the REQ-held-in-a-phase conditions change (mask 0x40 data in, 0x20 status/message).
ScsiSwitches
Timing (master clocks), provisional; tier in the comment. The reference’s ScsiBus class attributes, with its defaults.

Enums§

Phase
Update
What a queued drive timer does when it fires.

Constants§

ASC_INVALID_COMMAND
ASC_LBA_OUT_OF_RANGE
ASC_MEDIUM_NOT_PRESENT
CHECK_CONDITION
CMD_AUDIO_END
CMD_AUDIO_START
CMD_PAUSE
CMD_READ
CMD_READ_SUBQ
CMD_READ_TOC
CMD_REQUEST_SENSE
CMD_TEST_UNIT_READY
GOOD
SENSE_ILLEGAL_REQUEST
SENSE_NOT_READY

Functions§

command_length