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