dingusppc/devices/floppy/swim3.h

151 lines
3.8 KiB
C
Raw Normal View History

2021-12-12 20:40:04 +00:00
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Sander-Wozniak Machine 3 (SWIM3) definitions. */
#ifndef SWIM3_H
#define SWIM3_H
2022-02-07 22:04:13 +00:00
#include <devices/common/hwcomponent.h>
#include <devices/floppy/superdrive.h>
2021-12-12 20:40:04 +00:00
#include <cinttypes>
#include <memory>
class DmaBidirChannel;
class InterruptCtrl;
2021-12-12 20:40:04 +00:00
/** SWIM3 registers offsets. */
namespace Swim3 {
enum Swim3Reg : uint8_t {
Data = 0,
Timer = 1,
Error = 2,
Param_Data = 3,
Phase = 4,
Setup = 5,
Status_Mode0 = 6, // read: Status, write: zeroes to the mode register
Handshake_Mode1 = 7, // read: Handshake, write: ones to the mode register
2022-02-07 17:42:35 +00:00
Interrupt_Flags = 8,
2021-12-12 20:40:04 +00:00
Step = 9,
Current_Track = 10,
Current_Sector = 11,
Gap_Format = 12,
First_Sector = 13,
Sectors_To_Xfer = 14,
Interrupt_Mask = 15
};
2022-02-07 17:42:35 +00:00
/** Mode register bits. */
enum {
SWIM3_INT_ENA = 0x01,
2022-02-07 17:42:35 +00:00
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
2022-02-07 17:42:35 +00:00
SWIM3_GO_STEP = 0x80,
};
/** Interrupt flags. */
enum {
2022-11-17 17:02:53 +00:00
INT_TIMER_DONE = 0x01,
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
2022-02-07 17:42:35 +00:00
};
// SWIM3 internal states.
enum {
SWIM3_IDLE,
SWIM3_ADDR_MARK_SEARCH,
SWIM3_DATA_XFER,
};
2022-02-07 22:04:13 +00:00
class Swim3Ctrl : public HWComponent {
2021-12-12 20:40:04 +00:00
public:
Swim3Ctrl();
~Swim3Ctrl() = default;
static std::unique_ptr<HWComponent> create() {
return std::unique_ptr<Swim3Ctrl>(new Swim3Ctrl());
}
2022-02-07 22:04:13 +00:00
int device_postinit();
2021-12-12 20:40:04 +00:00
// SWIM3 registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
2022-02-15 14:53:18 +00:00
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
};
2022-02-07 17:42:35 +00:00
protected:
2022-11-17 17:02:53 +00:00
void update_irq();
void start_stepping();
void do_step();
void stop_stepping();
void start_disk_access();
void disk_access();
void stop_disk_access();
void init_timer(const uint8_t start_val);
uint8_t calc_timer_val();
2022-02-07 17:42:35 +00:00
2021-12-12 20:40:04 +00:00
private:
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
2022-02-15 14:53:18 +00:00
DmaBidirChannel* dma_ch;
2022-11-17 17:02:53 +00:00
uint8_t timer_val = 0; // internal timer that decrements at a 1 us rate
2021-12-12 20:40:04 +00:00
uint8_t setup_reg;
uint8_t mode_reg;
uint8_t error;
2021-12-12 20:40:04 +00:00
uint8_t phase_lines;
uint8_t int_reg;
2022-02-07 17:42:35 +00:00
uint8_t int_flags; // interrupt flags
2021-12-12 20:40:04 +00:00
uint8_t int_mask;
uint8_t pram; // parameter RAM: two nibbles = {late_time, early_time}
2022-02-07 17:42:35 +00:00
uint8_t step_count;
uint8_t cur_track;
uint8_t cur_sector;
uint8_t target_sect;
uint8_t format; // format byte from the last GCR/MFM address field
2021-12-12 20:40:04 +00:00
uint8_t first_sec;
uint8_t xfer_cnt;
uint8_t gap_size;
uint8_t rd_line;
int cur_state;
2022-02-07 17:42:35 +00:00
2022-11-17 17:02:53 +00:00
int one_us_timer_id = 0;
int step_timer_id = 0;
int access_timer_id = 0;
2022-02-07 22:04:13 +00:00
2022-11-17 17:02:53 +00:00
uint64_t one_us_timer_start = 0;
2022-02-07 22:04:13 +00:00
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq = 0;
2021-12-12 20:40:04 +00:00
};
}; // namespace Swim3
#endif // SWIM3_H