|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.7 ! root 7: //
! 8: // FDC (uPD72065B)
! 9: //
! 10:
1.1 root 11: #pragma once
12:
1.1.1.7 ! root 13: #include "event.h"
1.1 root 14:
15: enum fdc_phase_t {
16: PHASE_IDLE = 0,
17: PHASE_COMMAND,
18: PHASE_EXEC,
19: PHASE_RESULT,
20: };
21:
22: struct FDD {
23: bool motor; // モーターオン
24: bool seek; // シーク中/シーク完了割り込み保留中
1.1.1.7 ! root 25: bool ready;
1.1 root 26: };
27:
28: struct FDC {
29: int drivesel; // ドライブ選択
30: fdc_phase_t phase;
31: uint8 cmdbuf[10];
32: int cmdpos;
33: int cmdlen;
34: uint8 resbuf[10];
35: int respos;
36: int reslen;
37:
38: bool is2DD;
39: int accdrive; // アクセスドライブ番号
40:
41: // ステータスレジスタ
42: bool RQM; // Request For Master
43: int DIO; // Data Input/Output
44: #define DIOtoFDC (0)
45: #define DIOtoHost (1)
46: bool NDM; // Non-DMA Mode
47: bool CB; // FDC Busy
48:
49: uint8 srt;
50: uint8 hut;
51: uint8 hlt;
52: bool nd; // Non DMA
53:
54: // コマンド(下位5ビットのみにしたもの)
55: static const int CMD_MASK = 0x1f; // マスク
56: static const int CMD_READ_DIAGNOSTIC = 0x02; // %0M00_0010
57: static const int CMD_SPECIFY = 0x03; // %0000_0011
58: static const int CMD_SENSE_DEVICE_STATUS = 0x04; // %0000_0100
59: static const int CMD_WRITE_DATA = 0x05; // %MM00_0101
60: static const int CMD_READ = 0x06; // %MMS0_0110
61: static const int CMD_RECALIBRATE = 0x07; // %0000_0111
62: static const int CMD_SENSE_INTERRUPT_STATUS = 0x08; // %0000_1000
63: static const int CMD_WRITE_DELETED_DATA = 0x09; // %MM00_1001
64: static const int CMD_READ_ID = 0x0a; // %0M00_1010
65: static const int CMD_READ_DELETED_DATA = 0x0c; // %MMS0_1100
66: static const int CMD_WRITE_ID = 0x0d; // %0M00_1101
67: static const int CMD_SEEK = 0x0f; // %0000_1111
68: static const int CMD_SCAN_EQUAL = 0x11; // %MMS1_0001
69: static const int CMD_RESET_STANDBY = 0x14; // %0011_0100
70: static const int CMD_SET_STABNDBY = 0x15; // %0011_0101
71: static const int CMD_SOFTWARE_RESET = 0x16; // %0011_0110
72: static const int CMD_SCAN_LOW_OR_EQUAL = 0x19; // %MMS1_1001
73: static const int CMD_SCAN_HIGH_OR_EQUAL = 0x1d; // %MMS1_1101
74:
75: // ステータスレジスタ
76: static const int STAT_RQM = 0x80; // Request For Master
77: static const int STAT_DIO = 0x40; // Data Input/Output
78: static const int STAT_NDM = 0x20; // Non-DMA Mode
1.1.1.5 root 79: static const int STAT_CB = 0x10; // FDC Busy
1.1 root 80: static const int STAT_D3B = 0x08; // FD3 Busy
81: static const int STAT_D2B = 0x04; // FD2 Busy
82: static const int STAT_D1B = 0x02; // FD1 Busy
83: static const int STAT_D0B = 0x01; // FD0 Busy
84:
85: // リザルトステータス0
86: static const int ST0_IC_MASK = 0xc0;
87: static const int ST0_IC_AI = 0xc0; // AI: Attention Interrupt
88: static const int ST0_IC_IC = 0x80; // CI: Invalid Command
89: static const int ST0_IC_AT = 0x40; // AT: Abnormal Terminate
90: static const int ST0_IC_NT = 0x00; // NT: Normal Terminate
91: static const int ST0_SE = 0x20; // Seek End
92: static const int ST0_EC = 0x10; // Equipment Check
93: static const int ST0_NR = 0x08; // Not Ready
94: static const int ST0_HD = 0x04; // Head Address
95: static const int ST0_US_MASK = 0x03; // Unit Select
96:
97: // リザルトステータス3
98: static const int ST3_FT = 0x80; // Fault
99: static const int ST3_WP = 0x40; // Write Protect
100: static const int ST3_RY = 0x20; // Ready
101: static const int ST3_T0 = 0x10; // Track 0
102: static const int ST3_TS = 0x08; // Two Side
103: static const int ST3_HD = 0x04; // HD
104: static const int ST3_US_MASK = 0x03; // Unit Select
105: };
106:
1.1.1.6 root 107: class FDCDevice : public IODevice
1.1 root 108: {
1.1.1.2 root 109: using inherited = IODevice;
1.1.1.7 ! root 110:
1.1 root 111: static const int baseaddr = 0xe94000;
112:
113: public:
114: FDCDevice();
1.1.1.4 root 115: virtual ~FDCDevice() override;
1.1 root 116:
1.1.1.7 ! root 117: void ResetHard(bool poweron) override;
! 118:
! 119: // 強制レディ
! 120: void SetForceReady(bool force_ready_);
1.1 root 121:
1.1.1.2 root 122: protected:
123: // BusIO インタフェース
124: static const uint32 NPORT = 4;
1.1.1.5 root 125: uint64 Read(uint32 offset);
126: uint64 Write(uint32 offset, uint32 data);
127: uint64 Peek(uint32 offset);
1.1 root 128:
129: private:
130: uint32 ReadStatus();
131: uint32 ReadData();
132: uint32 ReadDriveStatus();
133: void WriteCmd(uint32);
134:
135: void idle_phase();
136: void exec_phase();
137: void result_phase();
138:
1.1.1.3 root 139: void Callback(Event& ev);
1.1 root 140:
141: void Interrupt();
142:
1.1.1.7 ! root 143: bool interrupt {}; // 割り込みを出している間は true
! 144:
! 145: struct FDC fdc {};
! 146: struct FDD fdd[4] {};
! 147:
! 148: bool force_ready {}; // 強制レディ
! 149:
1.1.1.6 root 150: Event event { this };
1.1 root 151:
152: // コマンドを名前に変換
153: static const char *cmd2name(uint32);
154:
155: // コマンド名一覧
156: static const char *cmdnames_str[];
157: };
1.1.1.4 root 158:
1.1.1.7 ! root 159: extern FDCDevice *gFDC;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.