--- nono/vm/fdc.h 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/fdc.h 2026/04/29 17:05:11 1.1.1.7 @@ -1,12 +1,16 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// FDC (uPD72065B) // #pragma once -#include "device.h" -#include "scheduler.h" +#include "event.h" enum fdc_phase_t { PHASE_IDLE = 0, @@ -18,6 +22,7 @@ enum fdc_phase_t { struct FDD { bool motor; // モーターオン bool seek; // シーク中/シーク完了割り込み保留中 + bool ready; }; struct FDC { @@ -71,7 +76,7 @@ struct FDC { static const int STAT_RQM = 0x80; // Request For Master static const int STAT_DIO = 0x40; // Data Input/Output static const int STAT_NDM = 0x20; // Non-DMA Mode - static const int STAT_CB = 0x10; // FDC Busy + static const int STAT_CB = 0x10; // FDC Busy static const int STAT_D3B = 0x08; // FD3 Busy static const int STAT_D2B = 0x04; // FD2 Busy static const int STAT_D1B = 0x02; // FD1 Busy @@ -99,24 +104,27 @@ struct FDC { static const int ST3_US_MASK = 0x03; // Unit Select }; -class FDCDevice - : public IODevice +class FDCDevice : public IODevice { - typedef IODevice inherited; - private: + using inherited = IODevice; + static const int baseaddr = 0xe94000; public: FDCDevice(); - virtual ~FDCDevice(); + virtual ~FDCDevice() override; + + void ResetHard(bool poweron) override; - virtual void ResetHard(); + // 強制レディ + void SetForceReady(bool force_ready_); - virtual uint64 Read8(uint32 addr); - virtual uint64 Read16(uint32 addr); - virtual uint64 Write8(uint32 addr, uint32 data); - virtual uint64 Write16(uint32 addr, uint32 data); - virtual uint64 Peek8(uint32 addr); + protected: + // BusIO インタフェース + static const uint32 NPORT = 4; + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + uint64 Peek(uint32 offset); private: uint32 ReadStatus(); @@ -128,14 +136,18 @@ class FDCDevice void exec_phase(); void result_phase(); + void Callback(Event& ev); + + void Interrupt(); + + bool interrupt {}; // 割り込みを出している間は true + struct FDC fdc {}; struct FDD fdd[4] {}; - void Callback(int); + bool force_ready {}; // 強制レディ - void Interrupt(); - - Event event {}; + Event event { this }; // コマンドを名前に変換 static const char *cmd2name(uint32); @@ -143,3 +155,5 @@ class FDCDevice // コマンド名一覧 static const char *cmdnames_str[]; }; + +extern FDCDevice *gFDC;