Something went wrong. Try again.
A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>//// SPDX-License-Identifier: MIT
//! The NCR 5380, which is what an Apple II SCSI Card has on it.//!//! It is the first single-chip SCSI controller and the part in almost//! everything that spoke SCSI in the middle 1980s -- the Macintosh Plus, SE//! and II as well as this card -- and it is barely a controller at all. "The//! NCR 5380 SCSI Interface Device appears as a set of eight registers to the//! controlling CPU. By reading and writing the appropriate registers, the CPU//! may initiate any SCSI bus activity or may sample and assert any signal on//! the SCSI bus. This allows the user to implement all or portions of the SCSI//! protocol in software" (NCR Corporation, 1986, §6.0, p. 10). So the chip//! holds almost no state of its own: arbitration and the REQ/ACK handshake are//! the two things it does without being told, and everything else is the//! firmware working the wires a register at a time.//!//! That is why this file is short and `scsi.zig` is not. The protocol lives on//! the bus; this is the window the 6502 sees it through.//!//! ## Four of the eight addresses are two registers//!//! Reading and writing the same address reaches different registers at four of//! the eight, which is the thing to keep hold of while reading any of this//! (§6.0, p. 10, and the Register Reference Chart, Appendix A7, p. 58)://!//! | address | read | write |//! | --- | --- | --- |//! | 0 | Current SCSI Data | Output Data |//! | 1 | Initiator Command | Initiator Command |//! | 2 | Mode | Mode |//! | 3 | Target Command | Target Command |//! | 4 | Current SCSI Bus Status | Select Enable |//! | 5 | Bus and Status | Start DMA Send |//! | 6 | Input Data | Start DMA Target Receive |//! | 7 | Reset Parity/Interrupts | Start DMA Initiator Receive |//!//! And one bit differs between the two halves of the Initiator Command//! Register itself: bit 5 reads as Lost Arbitration and writes as Differential//! Enable, bit 6 reads as Arbitration In Progress and writes as Test Mode.
const std = @import("std");const scsi = @import("scsi.zig");
/// The eight addresses, named by what a read of each answers.pub const Register = enum(u3) { current_data = 0, initiator_command = 1, mode = 2, target_command = 3, bus_status = 4, bus_and_status = 5, input_data = 6, reset_parity = 7,};
/// Initiator Command Register (address 1). The low five bits mean the same/// read or written; the top three do not.pub const icr_assert_data = 0x01;pub const icr_assert_atn = 0x02;pub const icr_assert_sel = 0x04;pub const icr_assert_bsy = 0x08;pub const icr_assert_ack = 0x10;/// Read: lost arbitration. Write: differential enable, which "is not used in/// the NCR 5380" (§6.2, p. 12).pub const icr_lost_arbitration = 0x20;/// Read: arbitration in progress. Write: test mode.pub const icr_arbitration_in_progress = 0x40;pub const icr_assert_rst = 0x80;
/// Mode Register (address 2).pub const mode_arbitrate = 0x01;pub const mode_dma = 0x02;pub const mode_monitor_busy = 0x04;pub const mode_enable_eop_interrupt = 0x08;pub const mode_enable_parity_interrupt = 0x10;pub const mode_enable_parity_checking = 0x20;pub const mode_target = 0x40;pub const mode_block_dma = 0x80;
/// Target Command Register (address 3), which is the phase lines.pub const tcr_assert_io = 0x01;pub const tcr_assert_cd = 0x02;pub const tcr_assert_msg = 0x04;pub const tcr_assert_req = 0x08;
/// Current SCSI Bus Status (address 4, read).pub const status_dbp = 0x01;pub const status_sel = 0x02;pub const status_io = 0x04;pub const status_cd = 0x08;pub const status_msg = 0x10;pub const status_req = 0x20;pub const status_bsy = 0x40;pub const status_rst = 0x80;
/// Bus and Status (address 5, read).pub const bas_ack = 0x01;pub const bas_atn = 0x02;pub const bas_busy_error = 0x04;pub const bas_phase_match = 0x08;pub const bas_interrupt_request = 0x10;pub const bas_parity_error = 0x20;pub const bas_dma_request = 0x40;pub const bas_end_of_dma = 0x80;
/// The chip, and the bus it is on.pub const Ncr5380 = struct { bus: scsi.Bus = .{},
/// The three registers that are only ever what was written to them. output_data: u8 = 0, initiator_command: u8 = 0, mode: u8 = 0, target_command: u8 = 0, select_enable: u8 = 0,
/// The byte latched off the bus, which is what the Input Data Register /// answers with: "the Input Data Register is a read-only register that is /// used to read latched data from the SCSI bus" (NCR Corporation, 1986, /// §6.1.3, p. 11). input_data: u8 = 0,
/// Whether the chip is asking for attention, and whether a DMA transfer /// has been started and not yet finished. interrupt: bool = false, end_of_dma: bool = false,
/// What a hardware reset does: "reset clears all internal registers" and /// leaves the bus alone to settle (§9.1, p. 23). pub fn reset(self: *Ncr5380) void { // The RESET pin clears the chip's own registers and drops the signals // the chip is driving -- but this is the initiator's chip, and the // target at the other end of the cable is not the chip's to reset. It // keeps asserting BSY and holding the phase, so a reset here leaves the // connection up and only forgets what the initiator had set. // // Tearing the whole bus down here (which resetting `self.bus` does, // since that is where the target's selection and phase live) is what // kept a IIgs from booting off the card: the firmware clears DMA mode // through this pin after every data phase, and doing so also dropped // the STATUS phase it was about to read, so it spent the rest of the // command timing out in its phase-wait loop. self.output_data = 0; self.initiator_command = 0; self.mode = 0; self.target_command = 0; self.select_enable = 0; self.input_data = 0; self.interrupt = false; self.end_of_dma = false; // The chip stops driving what it was driving: SEL, ATN, ACK and RST are // its outputs, as is BSY while it is an initiator, and the data lines. // REQ, the phase, and the target's BSY belong to the target. self.bus.sel = false; self.bus.atn = false; self.bus.rst = false; self.bus.ack = false; self.bus.initiator_busy = false; self.bus.out = 0; self.bus.driving = false; self.bus.handshaken = false; }
/// Whether the phase the target is driving matches the one the firmware /// said to expect, which is bit 3 of the Bus and Status Register. It is /// the check a driver makes before every DMA transfer, since the phase /// changing under it is how a target says the transfer is over. fn phaseMatches(self: *const Ncr5380) bool { const wanted = self.target_command & 0x07; return @intFromEnum(self.bus.phase) == wanted; }
pub fn read(self: *Ncr5380, register: Register) u8 { return switch (register) { // Transparent: whatever is on the lines this instant, whoever is // driving them. .current_data => self.bus.data(), // The low five bits read back as written; the top three are the // chip's answers about arbitration rather than what was put there. .initiator_command => (self.initiator_command & 0x9f) | (if (self.mode & mode_arbitrate != 0) @as(u8, icr_arbitration_in_progress) else 0), .mode => self.mode, // Bits 4 to 6 of the target command register read as nought, // which the Register Reference Chart draws as three zeroes where // the write side draws three don't-cares. .target_command => self.target_command & 0x8f, .bus_status => status: { var value: u8 = 0; if (self.bus.sel) value |= status_sel; if (self.bus.rst) value |= status_rst; if (self.bus.busy()) value |= status_bsy; if (self.bus.req) value |= status_req; if (self.bus.selected != null) { // The three lines are in the Target Command Register's // order in a `Phase` and somewhere else entirely here, so // they are moved one at a time rather than masked. const phase = @intFromEnum(self.bus.phase); if (phase & 0b001 != 0) value |= status_io; if (phase & 0b010 != 0) value |= status_cd; if (phase & 0b100 != 0) value |= status_msg; } break :status value; }, .bus_and_status => status: { var value: u8 = 0; if (self.bus.ack) value |= bas_ack; if (self.bus.atn) value |= bas_atn; if (self.phaseMatches()) value |= bas_phase_match; if (self.interrupt) value |= bas_interrupt_request; // DRQ is up when the target is asking for a byte in a phase // the firmware said it wanted, and only in DMA mode. if (self.mode & mode_dma != 0 and self.bus.req and self.phaseMatches()) value |= bas_dma_request; if (self.end_of_dma) value |= bas_end_of_dma; break :status value; }, // Latched rather than transparent, which is the difference between // this and address 0. .input_data => self.input_data, // "Reset Parity/Interrupts": reading it is what clears them. .reset_parity => clear: { self.interrupt = false; break :clear 0; }, }; }
pub fn write(self: *Ncr5380, register: Register, value: u8) void { switch (register) { .current_data => { self.output_data = value; self.bus.out = value; }, .initiator_command => { self.initiator_command = value; self.bus.sel = value & icr_assert_sel != 0; self.bus.atn = value & icr_assert_atn != 0; self.bus.rst = value & icr_assert_rst != 0; self.bus.driving = value & icr_assert_data != 0; // BSY and ACK are the initiator's only while it is not // pretending to be a target: "in order for the signals ATN and // ACK to be asserted on the SCSI bus, the TARGETMODE bit must // be reset" (§6.3, p. 13). if (self.mode & mode_target == 0) { self.bus.initiator_busy = value & icr_assert_bsy != 0; self.bus.ack = value & icr_assert_ack != 0; } if (self.bus.rst) self.interrupt = true; }, .mode => { const was = self.mode; self.mode = value; // Arbitration is one of the two things the chip does for // itself. There is nothing else on this bus contending for it, // so it is won as soon as it is asked for: the chip asserts // BSY and the identity in the Output Data Register, which is // what AIP then reports (§6.3, p. 14). if (value & mode_arbitrate != 0 and was & mode_arbitrate == 0) { self.bus.initiator_busy = true; self.bus.driving = true; } if (value & mode_arbitrate == 0) { self.initiator_command &= ~@as(u8, icr_lost_arbitration); } if (value & mode_dma == 0) self.end_of_dma = false; }, .target_command => self.target_command = value, // Address 4 written is the Select Enable Register: a mask of the // one identity this chip should answer a selection on. Nothing // selects an Apple II, so it is kept and never acted on. .bus_status => self.select_enable = value, // The three DMA starts. There is no DMA controller on an Apple II // SCSI Card: it moves bytes by pseudo-DMA, where the card's own // decode supplies DACK and the processor supplies the cycles, so // what these do here is arm the transfer and nothing more. .bus_and_status, .input_data, .reset_parity => self.end_of_dma = false, } self.bus.settle(); self.latch(); }
/// Takes the byte off the bus if the target is offering one, which is what /// fills the Input Data Register. fn latch(self: *Ncr5380) void { if (self.bus.req and self.bus.phase.toInitiator()) self.input_data = self.bus.in; }
/// One byte in or out through the card's pseudo-DMA port, which is what /// the firmware uses for the data phases: the card asserts DACK for the /// access, and the chip does the REQ/ACK handshake for it. /// /// This is `$C0n8` on the card. It is not one of the chip's eight /// registers -- it is the card's decode standing in for a DMA controller /// nobody fitted -- which is why it is a method rather than an address. pub fn pseudoDma(self: *Ncr5380, out: ?u8) u8 { const byte = if (self.bus.phase.toInitiator()) self.bus.in else 0; if (out) |value| { self.bus.out = value; self.bus.driving = true; } // The handshake the chip would have done for a real DACK: ACK up, the // byte moves, ACK down. self.bus.ack = true; self.bus.settle(); self.bus.ack = false; self.bus.settle(); self.latch(); return byte; }};
const testing = std.testing;
/// Drives one command the way the firmware does: arbitrate, select, hand over/// the descriptor block, move the data, take the status and the message.////// This is the whole of the protocol in twenty lines, which is the point of/// the chip: it does arbitration and the handshake and the 6502 does the rest.fn issue(chip: *Ncr5380, target: u3, cdb: []const u8, data_in: ?[]u8, data_out: ?[]const u8) !scsi.Status { // Arbitrate. The Output Data Register holds the identity to put on the // bus, which for a card is seven -- the highest priority. chip.write(.current_data, 0x80); chip.write(.mode, mode_arbitrate); try testing.expect(chip.read(.initiator_command) & icr_arbitration_in_progress != 0); try testing.expect(chip.read(.bus_status) & status_bsy != 0);
// Select: our identity and the target's on the data lines, SEL up, and // then BSY down so the target can answer with its own. chip.write(.current_data, @as(u8, 0x80) | (@as(u8, 1) << target)); chip.write(.initiator_command, icr_assert_data | icr_assert_sel | icr_assert_bsy); chip.write(.initiator_command, icr_assert_data | icr_assert_sel); try testing.expect(chip.read(.bus_status) & status_bsy != 0); // the target answered chip.write(.initiator_command, 0);
// The command phase, a byte at a time. try testing.expectEqual(scsi.Phase.command, chip.bus.phase); chip.write(.target_command, @intFromEnum(scsi.Phase.command)); for (cdb) |byte| { try testing.expect(chip.read(.bus_status) & status_req != 0); _ = chip.pseudoDma(byte); }
// Whatever phase the target went to. Data one way or the other, then // status, then the one message. while (true) { chip.write(.target_command, @intFromEnum(chip.bus.phase)); switch (chip.bus.phase) { .data_in => { const into = data_in orelse return error.UnexpectedDataIn; var at: usize = 0; while (chip.bus.phase == .data_in) : (at += 1) { const byte = chip.pseudoDma(null); if (at < into.len) into[at] = byte; } }, .data_out => { const from = data_out orelse return error.UnexpectedDataOut; for (from) |byte| _ = chip.pseudoDma(byte); // The target moves on when it has had them all. while (chip.bus.phase == .data_out) _ = chip.pseudoDma(0); }, .status => { const status: scsi.Status = @enumFromInt(chip.pseudoDma(null)); // And the message that ends it. chip.write(.target_command, @intFromEnum(scsi.Phase.message_in)); _ = chip.pseudoDma(null); try testing.expect(chip.bus.selected == null); // And let the bus go, which is what a driver does between // commands: the arbitrate bit has to fall before it can be // raised again, and leaving the data lines driven would hold // the next selection's identity wrong. chip.write(.mode, 0); chip.write(.initiator_command, 0); return status; }, else => return error.UnexpectedPhase, } }}
test "a disk answers who it is" { var disk: scsi.Disk = .{}; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
var answer: [36]u8 = @splat(0xee); const status = try issue(&chip, 6, &[_]u8{ 0x12, 0, 0, 0, 36, 0 }, &answer, null); try testing.expectEqual(scsi.Status.good, status); // Byte 0 is the peripheral device type, and nought is a direct-access // device -- a disk. Then the vendor and product, space padded. try testing.expectEqual(@as(u8, 0x00), answer[0]); try testing.expectEqualStrings("ZIG65 ", answer[8..16]); try testing.expectEqualStrings("SCSI HARD DISK ", answer[16..32]);}
test "an empty drive is not ready, and says why when asked" { var disk: scsi.Disk = .{}; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
// No image: the command fails rather than pretending. const status = try issue(&chip, 6, &[_]u8{ 0x00, 0, 0, 0, 0, 0 }, null, null); try testing.expectEqual(scsi.Status.check_condition, status);
// And a REQUEST SENSE says which kind of failure it was: not ready, with // the additional code for medium not present. var sense: [18]u8 = @splat(0); const sensed = try issue(&chip, 6, &[_]u8{ 0x03, 0, 0, 0, 18, 0 }, &sense, null); try testing.expectEqual(scsi.Status.good, sensed); try testing.expectEqual(@as(u8, 0x70), sense[0]); // current error, extended try testing.expectEqual(@intFromEnum(scsi.SenseKey.not_ready), sense[2]); try testing.expectEqual(@as(u8, 0x3a), sense[12]); // medium not present}
test "a disk says how big it is, and reads and writes its blocks" { const gpa = testing.allocator; const image = try gpa.alloc(u8, 64 * scsi.block_size); defer gpa.free(image); @memset(image, 0); for (0..scsi.block_size) |i| image[3 * scsi.block_size + i] = @truncate(i);
var disk: scsi.Disk = .{ .image = image }; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
// READ CAPACITY answers with the number of the *last* block, not how many // there are, and then the size of one. var capacity: [8]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, &capacity, null); try testing.expectEqual(@as(u32, 63), std.mem.readInt(u32, capacity[0..4], .big)); try testing.expectEqual(@as(u32, 512), std.mem.readInt(u32, capacity[4..8], .big));
// READ(6) block 3, and it is the block that was put there. var block: [scsi.block_size]u8 = @splat(0); const read = try issue(&chip, 6, &[_]u8{ 0x08, 0, 0, 3, 1, 0 }, &block, null); try testing.expectEqual(scsi.Status.good, read); for (0..scsi.block_size) |i| try testing.expectEqual(@as(u8, @truncate(i)), block[i]);
// WRITE(6) somewhere else, and it really lands in the image. var written: [scsi.block_size]u8 = @splat(0xa5); const wrote = try issue(&chip, 6, &[_]u8{ 0x0a, 0, 0, 9, 1, 0 }, null, &written); try testing.expectEqual(scsi.Status.good, wrote); try testing.expectEqual(@as(u8, 0xa5), image[9 * scsi.block_size]); try testing.expectEqual(@as(u8, 0xa5), image[10 * scsi.block_size - 1]);
// Two blocks at once are contiguous, which is what makes a multi-block // transfer one slice rather than a loop. var pair: [2 * scsi.block_size]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x08, 0, 0, 9, 2, 0 }, &pair, null); try testing.expectEqual(@as(u8, 0xa5), pair[0]); try testing.expectEqual(@as(u8, 0x00), pair[scsi.block_size]);}
test "reading past the end of the disk is refused rather than answered" { const gpa = testing.allocator; const image = try gpa.alloc(u8, 8 * scsi.block_size); defer gpa.free(image); @memset(image, 0); var disk: scsi.Disk = .{ .image = image }; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
const status = try issue(&chip, 6, &[_]u8{ 0x08, 0, 0, 20, 1, 0 }, null, null); try testing.expectEqual(scsi.Status.check_condition, status);
var sense: [18]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x03, 0, 0, 0, 18, 0 }, &sense, null); try testing.expectEqual(@intFromEnum(scsi.SenseKey.illegal_request), sense[2]); try testing.expectEqual(@as(u8, 0x21), sense[12]); // block address out of range}
test "a write protected disk refuses to be written and says so" { const gpa = testing.allocator; const image = try gpa.alloc(u8, 8 * scsi.block_size); defer gpa.free(image); @memset(image, 0); var disk: scsi.Disk = .{ .image = image, .write_protected = true }; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
var block: [scsi.block_size]u8 = @splat(0x5a); const status = try issue(&chip, 6, &[_]u8{ 0x0a, 0, 0, 1, 1, 0 }, null, &block); try testing.expectEqual(scsi.Status.check_condition, status); try testing.expectEqual(@as(u8, 0), image[scsi.block_size]);
var sense: [18]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x03, 0, 0, 0, 18, 0 }, &sense, null); try testing.expectEqual(@intFromEnum(scsi.SenseKey.data_protect), sense[2]);
// And a MODE SENSE says the same thing the other way about, which is the // bit a driver looks at before it tries. var mode_page: [4]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x1a, 0, 0, 0, 4, 0 }, &mode_page, null); try testing.expectEqual(@as(u8, 0x80), mode_page[2] & 0x80);}
test "a command the disk does not know is refused, not guessed at" { var disk: scsi.Disk = .{ .image = &.{} }; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
const status = try issue(&chip, 6, &[_]u8{ 0xdd, 0, 0, 0, 0, 0 }, null, null); try testing.expectEqual(scsi.Status.check_condition, status);
var sense: [18]u8 = @splat(0); _ = try issue(&chip, 6, &[_]u8{ 0x03, 0, 0, 0, 18, 0 }, &sense, null); try testing.expectEqual(@intFromEnum(scsi.SenseKey.illegal_request), sense[2]); try testing.expectEqual(@as(u8, 0x20), sense[12]); // invalid command operation code}
test "selecting nothing leaves the bus free" { var disk: scsi.Disk = .{}; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
chip.write(.current_data, 0x80); chip.write(.mode, mode_arbitrate); // Target 2, where there is nothing. chip.write(.current_data, 0x80 | 0x04); chip.write(.initiator_command, icr_assert_data | icr_assert_sel | icr_assert_bsy); chip.write(.initiator_command, icr_assert_data | icr_assert_sel); try testing.expect(chip.bus.selected == null); // Nothing asserted BSY back, so the bus reads as free once the initiator // lets go -- which is how the firmware knows there is no such device. chip.write(.initiator_command, 0); chip.write(.mode, 0); try testing.expect(chip.read(.bus_status) & status_bsy == 0);}
test "the reset line puts every device back and frees the bus" { const gpa = testing.allocator; const image = try gpa.alloc(u8, 8 * scsi.block_size); defer gpa.free(image); @memset(image, 0); var disk: scsi.Disk = .{ .image = image }; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
_ = try issue(&chip, 6, &[_]u8{ 0x00, 0, 0, 0, 0, 0 }, null, null);
chip.write(.initiator_command, icr_assert_rst); try testing.expect(chip.interrupt); try testing.expect(chip.bus.selected == null); try testing.expect(!chip.bus.busy()); // Every device now has something to say about why: a bus reset is a unit // attention. try testing.expectEqual(scsi.SenseKey.unit_attention, disk.sense);
// And reading address 7 is what clears the interrupt. chip.write(.initiator_command, 0); _ = chip.read(.reset_parity); try testing.expect(!chip.interrupt);}
test "the chip's RESET pin clears the chip but leaves the target connected" { // The RESET pin -- the card's $C0nB, not the SCSI RST signal -- resets the // initiator's chip and nothing else. The target on the cable keeps // asserting BSY and holding its phase, so the connection survives. The // Apple II SCSI Card firmware clears DMA mode through this pin after every // data phase, and modelling it as a whole-bus reset took the live STATUS // phase down with it -- which is why a IIgs would read one block, lose the // status it was about to read, and spend the rest of the command timing // out in its phase-wait loop. var disk: scsi.Disk = .{}; var chip: Ncr5380 = .{}; chip.bus.devices[6] = &disk;
// A live connection: the target selected, in the status phase, asserting // REQ, with the chip set up as it would be part way through a transfer. chip.bus.selected = 6; chip.bus.target_busy = true; chip.bus.phase = .status; chip.bus.req = true; chip.mode = mode_dma; chip.target_command = tcr_assert_io; chip.initiator_command = icr_assert_ack; chip.bus.ack = true;
chip.reset();
// The chip has forgotten its own settings and dropped what it was driving. try testing.expectEqual(@as(u8, 0), chip.mode); try testing.expectEqual(@as(u8, 0), chip.target_command); try testing.expect(!chip.bus.ack); // But the target is still selected, still in its phase, still asking. try testing.expectEqual(@as(?u3, 6), chip.bus.selected); try testing.expect(chip.bus.target_busy); try testing.expectEqual(scsi.Phase.status, chip.bus.phase); try testing.expect(chip.bus.req);}